-
I have a need to be able to bind the value that I assign to the ForceCulture attribute, so that I can display translations into different languages at different places on the screen. I currently have a ListView that is bound to a list of language codes and wish to display a phrase in English and the relevant language, for each language in the list. If I do this, then the language column displays all of the language codes, but the other columns always display the french translations <Window.Resources>
<DataTemplate x:Key="englishNameOfLanguageCellTemplate">
<TextBlock Text="{lex:LocText Key='EnglishNameOfLanguage', ForceCulture=fr'}"/>
</DataTemplate>
<DataTemplate x:Key="localNameOfLanguageCellTemplate">
<TextBlock Text="{lex:LocText Key='LocalNameOfLanguage', ForceCulture=fr}"/>
</DataTemplate>
</Window.Resources>
<ListView ItemsSource="{Binding Codes}" Margin="10,36,703,357">
<ListView.View>
<GridView>
<GridViewColumn Header="Language" Width="auto" DisplayMemberBinding="{Binding}" />
<GridViewColumn Header="English name" Width="auto" CellTemplate="{StaticResource englishNameOfLanguageCellTemplate}" />
<GridViewColumn Header="Local name" Width="auto" CellTemplate="{StaticResource localNameOfLanguageCellTemplate}" />
</GridView>
</ListView.View>
</ListView> What I'd hoped to be able to do is...
Unfortunately this produces the error...
Is there a way of dynamically setting the ForceCulture attribute? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, @belugabob! But I have one idea how you can deal with it. You can write converter like this: public class CultureNameConverter : TypeValueConverterBase, IValueConverter
{
/// <inheritdoc />
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var valueCulture = value as CultureInfo;
if (valueCulture == null)
return string.Empty;
var key = parameter as string;
if (string.IsNullOrEmpty(key))
return string.Empty;
return Ressourcen.ResourceManager.GetObject(key, valueCulture);
}
/// <inheritdoc />
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
} and using: <TextBlock Text="{Binding Converter={c:CultureNameConverter}, ConverterParameter='EnglishNameOfLanguage'}" />
<TextBlock Text="{Binding Converter={c:CultureNameConverter}, ConverterParameter='LocalNameOfLanguage'}" /> So instead of I don't test it, but it should work :) |
Beta Was this translation helpful? Give feedback.
Hello, @belugabob!
Unfortunately, it's really very hard to replace
ForceCulture
fromstring
toBinding
. I'll have some ideas how to make it's more possible.But I have one idea how you can deal with it. You can write converter like this: