wpf 在某些单元格中隐藏DatagridCheckBoxColumn中的复选框

lhcgjxsq  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(129)

我有一个带有DatagridCheckboxColumn的Datagrid。我只希望选中的行显示复选框。我试着用可见性,但然后细胞-显然-消失了。所以你不能踢他们,他们没有相同的背景颜色。
有没有可能通过绑定来实现这一点?
带有隐藏复选框的Datagrid
x1c 0d1x的数据
下面是我的xaml代码:

<DataGrid   Name="dtgDecodedMsg"
        CanUserSortColumns="False"
        CanUserAddRows="False"
        CanUserReorderColumns="False"
        HeadersVisibility="Column"
        IsTabStop="False"
        ClipboardCopyMode="IncludeHeader"
        SelectedIndex="{Binding DecodeSelectedGridIdx, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
        ItemsSource="{Binding Path=MsgTypGridLineListVar, UpdateSourceTrigger=PropertyChanged}" 
        AutoGenerateColumns="False" 
        Margin="10,111,10,0">
        <DataGrid.Columns>
          <DataGridCheckBoxColumn Header="..." Width="25">
            <DataGridCheckBoxColumn.CellStyle>
              <Style TargetType="{x:Type DataGridCell}">
                <Style.Triggers>
                  <Trigger Property="IsSelected" Value="True">
                    <Setter Property="BorderBrush" Value="LightBlue"/>
                    <Setter Property="BorderThickness" Value="2"/>
                  </Trigger>
                </Style.Triggers>
                <Setter Property="Background" Value="{Binding HideCell.CellColor}"/>
                <Setter Property="BorderBrush" Value="{Binding HideCell.CellColor}"/>
                <Setter Property="Visibility" Value="{Binding HideCell.CellVisibility}"/>
              </Style>
            </DataGridCheckBoxColumn.CellStyle>
          </DataGridCheckBoxColumn>
          <DataGridTextColumn Header="Value" Binding="{Binding ValueTelegramCell.CellValue}" IsReadOnly="True" Width="*">
            <DataGridTextColumn.CellStyle>
              <Style TargetType="{x:Type DataGridCell}">
                <Style.Triggers>
                  <Trigger Property="IsSelected" Value="True">
                    <Setter Property="BorderBrush" Value="LightBlue"/>
                    <Setter Property="BorderThickness" Value="2"/>
                  </Trigger>
                </Style.Triggers>
                <Setter Property="Foreground" Value="{Binding ValueTelegramCell.TextColor}"/>
                <Setter Property="Background" Value="{Binding ValueTelegramCell.CellColor}"/>
                <Setter Property="BorderBrush" Value="{Binding ValueTelegramCell.CellColor}"/>
              </Style>
            </DataGridTextColumn.CellStyle>
          </DataGridTextColumn>
        </DataGrid.Columns>
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Setter Property="Visibility" Value="{Binding RowVisible , Mode=OneWay}"/>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>

字符串
因此,atm我绑定的可见性的细胞,但这并没有给予我想要的结果..请参阅:

<Setter Property="Visibility" Value="{Binding HideCell.CellVisibility}"/>


它应该如下所示:(可单击单元格以选择整行)
Datagrid应该是什么样子



谢谢你,谢谢

ruarlubt

ruarlubt1#

我得到了一个适合我的解决方案,如果有人有同样的问题,这里是答案:
我现在使用Elementstyle直接访问复选框。

<DataGridCheckBoxColumn Header="..." Width="25">
            <DataGridCheckBoxColumn.CellStyle>
              <Style TargetType="{x:Type DataGridCell}">
                <Style.Triggers>
                  <Trigger Property="IsSelected" Value="True">
                    <Setter Property="BorderBrush" Value="LightBlue"/>
                    <Setter Property="BorderThickness" Value="2"/>
                  </Trigger>
                </Style.Triggers>
                <Setter Property="Background" Value="{Binding HideCell.CellColor}"/>
                <Setter Property="BorderBrush" Value="{Binding HideCell.CellColor}"/>
                <Setter Property="Focusable" Value="{Binding HideCell.CheckBoxEnabled}"/>
              </Style>
            </DataGridCheckBoxColumn.CellStyle>
            <DataGridCheckBoxColumn.ElementStyle>
              <Style TargetType="CheckBox">
                <Setter Property="Visibility" Value="{Binding HideCell.CellVisibility}"/>
              </Style>
            </DataGridCheckBoxColumn.ElementStyle>
          </DataGridCheckBoxColumn>

字符串

相关问题