有的时候,数据库存的是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"  />

 

相关文章:

  • 2022-12-23
  • 2021-05-03
  • 2021-06-18
  • 2021-07-22
  • 2021-06-03
  • 2021-11-15
  • 2021-08-29
  • 2021-09-26
猜你喜欢
  • 2021-10-04
  • 2021-06-20
  • 2022-03-01
  • 2021-12-07
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案