Hello,
I have a UserControl that displays some text of a DP of the UserControl. For this a converter is used. I understand that the culture parameter is the "en-US" culture, unless you specify a different culture in the ConverterCulture value of the binding or the xml:lang attribute.
But how can I change to culture from outside of the UserControl???
This is my UserControl:
<UserControl x:Class="CultInfoConverter.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:CultInfoConverter"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Tag="{x:Null}">
<UserControl.Resources>
<my:MyConverter x:Key="MyConverter" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal" >
<TextBlock Margin="8">My converter culture is</TextBlock>
<TextBlock FontWeight="Bold" Text="{Binding Tag, Converter={StaticResource MyConverter}}" />
</StackPanel>
</UserControl>
For demonstration purposes the converter simply returns the name of the culture info passed to it:
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return culture.Name;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
In my window I have two instances of the user control, and each should display a different culture. But both just show the standard "en-US".
<Window x:Class="CultInfoConverter.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:my="clr-namespace:CultInfoConverter">
<StackPanel>
<TextBlock Margin="8">using xml:lang="de-DE"</TextBlock>
<my:MyUserControl xml:lang="de-DE"/>
<TextBlock Margin="8">using xml:lang="fr-FR"</TextBlock>
<my:MyUserControl xml:lang="fr-FR"/>
</StackPanel>
</Window>