<DataGridTextColumn Header="Amount($)" Width="*" Binding="{Binding Path = Amount}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Tran_Code}" Value=**"DEP"**>
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
不是只有一个值(截至现在是DEP),而是应为某些值启用单元格
答案 0 :(得分:0)
您可以使用转换器:
<DataGridTextColumn Header="Amount($)" Width="*" Binding="{Binding Path = Amount}" Visibility="Binding Path = Tran_Code, Converter={StaticResource VisibilityConverter}"></DataGridTextColumn>
public class VisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string transcode = value.ToString();
if (transcode == 1)
return Visibility.Hidden;
else
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
答案 1 :(得分:0)
this.mydatagrid.Columns [2] .Visibility = Visibility.Hidden;
您可以添加要隐藏的列的索引。