WPF / Silverlight Binding Convertor 用法
需要在三个地方做处理:
1 . 定义Convertor
public class RememberStatusConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var rememberStatus = (RememberStatus)value;
switch (rememberStatus)
{
case RememberStatus.NotRemember:
return "(无)";
case RememberStatus.Remembering:
return "记忆中...";
default:
return "已记住";
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
2 . 在XAML文件中加入资源
<BLL:RememberStatusConvertor x:Key="rememberStatusConvertor"/>
3 . 在XAML中使用资源
<TextBlock Grid.Column="2" Text="{Binding Path=Word.RememberStatus,Converter={StaticResource rememberStatusConvertor}}"
FontSize="28" Style="{StaticResource listboxTextBlock}"/>