日期:2014-05-20 浏览次数:21038 次
// Window1.xaml.cs
namespace WpfApplication1
{
public class DataConverter : IValueConverter
{
enum EnumValues { 经销 = 1, 营销 = 2, 生产 = 3 }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (EnumValues)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:local="clr-namespace:WpfApplication1">
<Window.Resources>
<local:DataConverter x:Key="dataConverter" />
</Window.Resources>
<Grid>
<my:DataGrid Name="dataGrid1">
<my:DataGrid.Columns>
<my:DataGridTextColumn Binding="{Binding cat, Converter={StaticResource dataConverter}}" />
</my:DataGrid.Columns>
</my:DataGrid>
</Grid>
</Window>