有的时候,数据库存的是0,1,3,但是页面显示的时候0:未读,已读。。。
1.定义转换器
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
namespace Glodon.Module.DocRegisterManage.Help
{
public class StateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (int.Parse(value.ToString()) == 1)
{
return "A";
}
else if (int.Parse(value.ToString()) == 2)
{
return "B";
}
else
{
return "C";
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
2.在XMAL文件引入转换器命名空间
xmlns:helper="clr-namespace:Glodon.Module.DocRegisterManage.Help"
3.声明资源
<UserControl.Resources>
<helper:StateConverter x:Key="StateConvert"/>
<helper:DataContextProxy x:Key="DataContextProxy" />
4.在gv里面使用资源
<TR:GridViewDataColumn IsReadOnly="True" DataMemberBinding="{Binding DState,Converter={StaticResource StateConvert}, Mode=OneWay}" Header="状态" IsFilterable="False" Width="80" HeaderTextAlignment="Center" />