我找到了一种在 wpf 数据网格中将布尔值转换为 yes/no 而不是 True/False 的方法:https ://stackoverflow.com/a/17089837/1646494 ,但是一旦完成,此列就不可排序。我的代码如下:
<DataGridTextColumn Header=" Consolidated Company " IsReadOnly="True" MinWidth="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="5,0,5,0" />
<Style.Triggers>
<DataTrigger Binding="{Binding lRollupCompany}" Value="True">
<Setter Property="Text" Value="Yes" />
</DataTrigger>
<DataTrigger Binding="{Binding lRollupCompany}" Value="False">
<Setter Property="Text" Value="No" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
试图让排序再次工作只会使列恢复为显示真/假...
<DataGridTextColumn Header=" Consolidated Company " Binding="{Binding lRollupCompany}" IsReadOnly="True" MinWidth="100">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="5,0,5,0" />
<Style.Triggers>
<DataTrigger Binding="{Binding lRollupCompany}" Value="True">
<Setter Property="Text" Value="Yes" />
</DataTrigger>
<DataTrigger Binding="{Binding lRollupCompany}" Value="False">
<Setter Property="Text" Value="No" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
有没有不涉及转换器的解决方案?