silverlight application wide date
Is there a way to define a application wide format for the dates in Silvelight. So far I've tried to add this code in App_Startup:
CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy";
culture.DateTimeFormat.FullDateTimePattern = "dd-开发者_如何转开发MM-yyyy";
culture.DateTimeFormat.ShortTimePattern = "dd-MM-yyyy";
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
But all my date binding don't take this into consideration.
Regards,
Create a string resource in your App.xaml
<System.String x:Key="MyDateFormat">dd-MM-yyyy</System.String>
And use it as a static resource in your bindings' string format
<TextBlock Text={Binding MyDateProperty, StringFormat={StaticResource MyDateFormat}} />
I haven't tested this, but that would be my first try.
Try accepted answer from here - DateTime Not showing with currentculture format in Datagrid,ListView.
This works for WPF, you can try it for Silverlight to make it respect your culture.
There is a partial solution for this here: http://timheuer.com/blog/archive/2010/08/11/stringformat-and-currentculture-in-silverlight.aspx
This may not work at the application level though - you may need to apply the solution to various other classes e.g. your child windows.
精彩评论