I would like default culture/language to be defined as resource in order to provide consistent displaying of selected labels. It seems, however it is not possible to define neither Language
(XMLLanguage) nor ConverterCulture
(CultureInfor) resource, it does not seem to be possible to use a string
resource neither:
<TextBlock Text="{Binding Source={x:Static sys:DateTime.Now},
Mode=OneWay, StringFormat={StaticResource DateFormat},
ConverterCulture={StaticResource DefaultCulture},
Language={StaticResource DefaultLang}/>
//....
<Grid.Resources>
<sys:String x:Key="DefaultCutureString">en-GB</sys:String>
<win:XmlLanguage xmlns:win="clr-namespace:System.Windows.Markup;assembly=PresentationFramework" x:Key="DefaultLang">en-GB</win:XmlLanguage>
<g:CultureInfo xmlns:g="clr-namespace:System.Globalization;assembly=mscorlib" x:Key="DefaultCuture">
<x:Arguments>
<sys:String>en-GB</sys:String>
</x:Arguments>
</g:CultureInfo>
</Grid.Resources>
How can I define and apply Culture/Language using Resource?
XmlLanguage
and CultureInfo
have no default parameterless constructors which means you cannot instantiate them in XAML.
But you could create the resources programmatically and then add them to Grid.Resources
(just give the Grid
and x:Name
of "grid" or similar in the XAML markup to be able to identify it in the code):
grid.Resources["DefaultLang"] = XmlLanguage.GetLanguage("en-GB");
grid.Resources["DefaultCuture"] = new System.Globalization.CultureInfo("en-GB");