public class SexConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value,Type targettype,object parameter,System.Globalization.CultureInfo culture)
{
//if (targettype != typeof(string)) throw new InvalidOperationException("The target must be a integer!");
if (value != null)
return (value.ToString().ToLower() == "false" ? "女" : "男");
else
return "";
}
public object ConvertBack(object value,System.Globalization.CultureInfo culture)
{
//if (targettype != typeof(Int32)) throw new InvalidOperationException("The target must be a String!");
return (value.ToString() == "女" ? 0 : 1);
}
}
<UserControl x:Class="YY.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:YY"
d:DesignHeight="400" d:DesignWidth="600" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<UserControl.Resources>
<local:SexConverter x:Key="sexConvert"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid AutoGenerateColumns="False" IsReadOnly="True" Height="297" HorizontalAlignment="Left" Margin="10,10,0" Name="dadisplay" VerticalAlignment="Top" Width="578" RowEditEnded="dadisplay_RowEditEnded">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding UserName,Mode=TwoWay}" Header="用户名" Width="200"/>
<sdk:DataGridTextColumn Binding="{Binding Mode=OneWay,Path=RegDate,StringFormat=/{0:d/}}" Header="注册时间" Width="100"/>
<sdk:DataGridTextColumn Binding="{Binding Activation,Converter={ StaticResource sexConvert}}" Header="Test" CanUserSort="True" CanUserResize="False" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<Button Content="删除" Height="23" HorizontalAlignment="Left" Click="btDel_Click" Margin="86,323,0" Name="btDel" VerticalAlignment="Top" Width="75" />
<Button Content="添加" Height="23" HorizontalAlignment="Left" Click="btAdd_Click" Margin="178,0" Name="btAdd" VerticalAlignment="Top" Width="75" />
</Grid>
</UserControl>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。