WP7 アプリで Web サービスから取得した静的テキストを使用したいと考えています。各テキストには Name (識別子) と Content プロパティがあります。
たとえば、テキストは次のようになります。
Name = "M43";
Content = "This is the text to be shown";
次に、テキストの名前 (つまり、識別子) を に渡したいと思いIValueConverter
ます。これにより、名前が検索され、テキストが返されます。
コンバーターは次のようになると考えました。
public class StaticTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return App.StaticTexts.Items.SingleOrDefault(t => t.Name.Equals(value)).Content;
}
return null;
}
}
次に、XAML で:
<phone:PhoneApplicationPage.Resources>
<Helpers:StaticTextConverter x:Name="StaticTextConverter" />
</phone:PhoneApplicationPage.Resources>
...
<TextBlock Text="{Binding 'M43', Converter={StaticResource StaticTextConverter}}"/>
ただし、これは機能していないようで、値をコンバーターに正しく渡すかどうかはわかりません。
誰か提案はありますか?