改变 Silverlight 应用程序的文化

发布于 2024-09-08 10:59:01 字数 1073 浏览 0 评论 0原文

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

<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}"/>

这绑定得很好,但日期始终显示为美国风格(月/日/年),而我想向它们显示英国风格(日/月/年)。我尝试使用托管应用程序的页面上

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

和 Silverlight 应用程序的 Application_Start 上的

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

HTML 标记来设置区域性,但这些都没有任何区别。我有一个实现 IValueConverter 接口的自定义类,我在 Convert 方法上添加了断点,并且传入的 CultureInfo 参数是 en-US,如何更改区域性?

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}"/>

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" />

and on Application_Start of my Silverlight application

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森林很绿却致人迷途 2024-09-15 10:59:01

将以下行添加到我的表单的构造函数解决了此问题:

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

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

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

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

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

等待我真够勒 2024-09-15 10:59:01

从代码中设置值违背了 MVVM 和依赖属性方法:您可能想查看这篇文章:
如何切换 UI 文化Silverlight 中的动态数据绑定

Setting the value from code kind of goes against the MVVM and dependency property approach: you might want to see this SO article:
How to switch UI Culture of data binding on the fly in Silverlight

昔梦 2024-09-15 10:59:01

在转换器中使用以下代码

CultureInfo ci = new CultureInfo("en-GB");
return value.ToString(ci);

In the Converter use the below code

CultureInfo ci = new CultureInfo("en-GB");
return value.ToString(ci);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文