views:

53

answers:

2

In WPF I am trying to Bind a Date property to Datagrid, and If I only have the date Property binded as DateTime format I can sort it in the datagrid.

And Here I have to show the regional Date, If the user changes the Region and Language settings, The application should show the resepective time format.

Here comes the Issue, When the Date is in string Format , it shoes according to the region settings, but when the property is binded in DateTime format the date is dafaulted to American Format rather than showing with currect region settings.

So, If I have string format the sorting by column doesnt work, and if its in DateTime format, it does convert to regional settings

A: 

That's because the binding system uses the culture defined by the FrameworkElement.Language property, which doesn't automatically match the current culture (which is a bit silly IMO, but that's the way it is...).

Fortunately there's an easy way around it, you just need to override the metadata for the Language property in your application static constructor, as shown here:

public partial class App : Application
{
    static App()
    {
        FrameworkElement.LanguageProperty.OverrideMetadata(
            typeof(FrameworkElement),
            new FrameworkPropertyMetadata(
                XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
    }
}
Thomas Levesque
Thanks a Lot Thomas, This is the exact solution I was expecting.But Isnt this a bug in .NET Framework.
crazy9
A: 

The Localization sample of the WPF Application Framework (WAF) shows how to solve your issue.

jbe
ya sure I will look into that, Thanks.
crazy9