我可以从页面类设置 silverlight 应用程序的区域性吗?
在我的 SL 应用程序中,我有一个连接到 Web 服务的页面来检索一些文化信息,例如日期格式。由于此信息在 silverlight 应用程序实例化时未知,因此我无法在公共 App() 构造函数中设置此信息。以下几行似乎不适用于页面类内服务调用的异步完成方法:
var dateFormatString = e.Result.DateFormatString;
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = dateFormatString;
Is there a way to set theculture of the silverlight application from a page class?
In my SL application, I have a page that connects to a web service to retrieve some culture information such as date formats. As this information is not known at the instantiation of the silverlight application, I cannot set this in the public App() constructor. The following lines don't seem to work in the async completed method of the service call within the page class:
var dateFormatString = e.Result.DateFormatString;
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = dateFormatString;
Is there a way to set the culture of the silverlight application from a page class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其设置在主线程中(您的 asyncCompleted 可能在不同的线程上运行)。
如果您不知道该怎么做,请告诉我。
没有必要克隆文化。 (代码中的第 2 行)。
只需直接设置即可:
** 编辑添加了从 UI 线程调用的示例代码。
您始终可以将状态传递给异步 WCF 调用。在这种情况下,我正在传递一个调度程序。
调用回调后,使用 Dispatcher 更改 UI 线程中的 UI 区域性。
这是我随手写下的,但应该足以让您了解需要做什么。
** 编辑2(回答问题)
如果您手边有一个UIElement,您可以使用它的Dispatcher 属性。
否则使用静态:
Set it in the main thread (your asyncCompleted is probably running on a different thread).
Let me know if you do not know how to do this.
There is no need to clone the Culture. (line 2 in your code).
Just set it directly:
** EDIT added sample code to call from UI Thread.
You can always pass state to an async wcf call. In this case I am passing a Dispatcher.
Once the callback is called use the Dispatcher to change the UI Culture in the UI thread.
I wrote this off the top of my head, but should be sufficient to give you an idea of what you need to do.
** EDIT 2 (answer question)
If you have a UIElement handy, you can use it's Disptacher property.
Otherwise use the static: