views:

30

answers:

1

Hi,

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?

A: 

In the Converter use the below code

CultureInfo ci = new CultureInfo("en-GB");
return value.ToString(ci);
Ragunathan
Would I need to use a converter for each DataColumn/TextBlock that displays a date?
Fermin
yes. But if you want to use global, In the MainPage constructor or Loaded event use below (No need for converter here) CultureInfo en = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentCulture = en;
Ragunathan
As I said in my initial post i've already tried setting the CurrentCulture in the Application_Start event and it doesn't change how the dates are shown.
Fermin