level 7
public class SexConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
bool tmp = (bool)value;
if (tmp)
return "男";
else
return "女";
}
catch (Exception ex)
{
return value;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Person p = new Person() { name = "张三", sex = false };
lbl2.DataContext = p;
<Label Name="lbl2" Grid.Row="1" Width="200" Height="55" FontSize="25" VerticalAlignment="Top"
Content="{ Binding Path=sex,Converter={StaticResource sexConverter}}"></Label>
2014年05月08日 05点05分
3
静态类转换,很常见的方法
2014年06月28日 03点06分
level 7
有三种解决方法,第一种就是在读取数据后循环转换下。第二种和第三中就是页面转换。转换有页面调用静态方法,方法直接写转换。第二种就是页面trigger。具体代码我就不写了,可以根据我的思路百度具体使用方法,百度比我更清楚。
2014年06月24日 08点06分
5