I use a set of texts derived from a web service that should be used for various controls.
The easiest and most dynamic way to do this, in my opinion, is to use IValueConverter to get this text as follows:
public class StaticTextConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter != null && parameter is string) { return App.StaticTexts.Items.SingleOrDefault(t => t.Name.Equals(parameter)).Content; } return null; } }
And then in XAML I pass the text identifier ('Name') to the converter:
<phone:PhoneApplicationPage.Resources> <Helpers:StaticTextConverter x:Name="TextConverter" /> </phone:PhoneApplicationPage.Resources> <TextBlock Text="{Binding Converter={StaticResource TextConverter}, ConverterParameter=M62}" />
Then, to change the text of some control, all you need to do is either change the identifier in the parameter or change the text itself from some web interface.
My problem
So that the value converter is included only in some DataTemplate context where the ItemSource was installed, as if only Binding works there.
Whenever I use this method elsewhere, the value converter is simply not called.
Does anyone have any idea what I can do wrong?
source share