改变Silverlight应用程序的文化 [英] Change culture of Silverlight application

查看:88
本文介绍了改变Silverlight应用程序的文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Silverlight应用程序.我有一些数据网格/文本块,在其中使用标准绑定来显示值,其中一些是日期.例如

I am working on a Silverlight app at the moment. I have a few datagrids/textblocks where I use standard binding to show values, some of which are dates. e.g.

<sdk:DataGrid AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding Path=MyCollection}">
  <sdk:DataGrid.Columns>
    <sdk:DataGridTextColumn Binding="{Binding Path=Name, Mode=OneWay}" Header="Agent"/>
    <sdk:DataGridTextColumn Binding="{Binding Path=UpdateTime, Mode=OneWay}" Header="Update Time"/>
  </sdk:DataGrid.Columns>
</sdk:DataGrid>
<TextBlock Text="{Binding Path=LastUpdatedTime}"/>

这可以很好地绑定,但是日期始终显示为美式风格(m/d/y),而我想将它们显示为英式风格(d/m/y).我曾尝试使用托管应用程序的页面上的两个HTML标签设置区域性

This binds fine but the dates are always shown as US style (m/d/y) whereas I want to show them UK style (d/m/y). I have tried setting the culture using both the HTML tags on the page hosting the application

<param name="uiculture" value="en-GB" />
<param name="culture" value="en-GB" />

以及我的Silverlight应用程序的Application_Start

and on Application_Start of my Silverlight application

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

但这些都不起作用.我有一个实现IValueConverter接口的自定义类,我在Convert方法上添加了一个断点,传入的CultureInfo参数是en-US,如何更改区域性?

but neither of these make any difference. I have a custom class that implements IValueConverter interface, I added a breakpoint on the Convert method and the CultureInfo parameter that is passed in is en-US, how do I change the culture?

推荐答案

在我的表单的构造函数中添加以下行可解决此问题:

Adding the following line to the constructor of my form fixed this issue:

this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);

来自 http://timheuer .com/blog/archive/2010/08/11/stringformat-and-currentculture-in-silverlight.aspx

这篇关于改变Silverlight应用程序的文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆