In my case:
I have a TextBlock Binding to a property of type DateTime.
I want it to be displayed as the Regional settings of the User says.
<TextBlock Text="{Binding Date, StringFormat={}{0:d}}" />
I am setting Language property as WPF XAML Bindings and CurrentCulture Display
says:
this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);
But with this line of code it just displays the text as the default format of CultureInfo
with IetfLanguageTag of CurrentCulture says, not as the effective value selected in systems region settings says:
(e.g. for "de-DE" dd.MM.yyyy is used instead of selected yyyy-MM-dd)
Is there a way Binding uses the correct format without defining ConverterCulture on every single Binding?
In code
string.Format("{0:d}",Date);
uses the right Culture settings.
edit:
another way which doesn't work as desired (like this.Language = ... does):
xmlns:glob="clr-namespace:System.Globalization;assembly=mscorlib"
and
<Binding Source="{x:Static glob:CultureInfo.CurrentCulture}"
Path="IetfLanguageTag"
ConverterCulture="{x:Static glob:CultureInfo.InvariantCulture}" />
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…