开发者

WPF DataGridCheckBoxColumn: how to hide the checkbox if the binding value is null?

I have a datagrid with a DataGridCheckBoxColumn binding to nullable bool. I'd like to hide the checkbox completely if the value is null. I tried the following trigger, but it doesn't work:

<Style TargetType="CheckBox">
    <Style.Triggers>
        <Trigger Property="IsChecked" Value="{x:Null}">
            <Setter Property="Visibility" Value="Hidden"/>
        </Trigger>
    </Style.Triggers>
</Style>

Is it p开发者_JAVA技巧ossible at all? Your help is much appreciated!


There are always two styles in a DataGrid, the ElementStyle and the EditingElementStyle, your style should be applied as ElementStyle, then you can still edit the checkbox but it won't be visible when not in edit mode if null. Also the three states need to be enabled.

<DataGridCheckBoxColumn Binding="{Binding MyNullableBool}" IsThreeState="True">
    <DataGridCheckBoxColumn.ElementStyle>
        <Style TargetType="CheckBox">
            <Style.Triggers>
                <Trigger Property="IsChecked" Value="{x:Null}">
                    <Setter Property="Visibility" Value="Hidden"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜