【问题标题】:Disable row selection datagrid WPF when a property is set to a value将属性设置为值时禁用行选择数据网格 WPF
【发布时间】:2019-09-27 01:42:50
【问题描述】:

如果属性设置为某个值,我想禁用行选择

我试过了:

<DataGrid ...>
   <DataGrid.CellStyle>
     <Style TargetType="DataGridCell">
       <Style.Triggers>
          <DataTrigger Binding="{Binding Path=IsBusy}" Value="True">
            <Setter Property="here I don't know" Value="False" />
          </DataTrigger>
       </Style.Triggers>
     </Style>
   </DataGrid.CellStyle>
</DataGrid>

我不想禁用整个 DataGrid,因为水平滚动不再可滚动,所以我避免这样做。

【问题讨论】:

标签: c# wpf


【解决方案1】:

如果您想取消选择整行,请尝试使用 RowStyle,并在您的数据触发器为 true 时将属性 IsSelected 设置为 false:

<DataGrid>
   <DataGrid.RowStyle>
     <Style TargetType="DataGridRow">
       <Style.Triggers>
          <Setter Property="Foreground" Value="Black" />
          <DataTrigger Binding="{Binding Path=IsBusy}" Value="True">
            <Setter Property="IsSelected" Value="False" />
          </DataTrigger>
          <Trigger Property="IsSelected" Value="False">
            <Setter Property="Foreground" Value="Black" />
          </Trigger>
       </Style.Triggers>
     </Style>
   </DataGrid.RowStyle>
   <DataGrid.CellStyle>
       <Style TargetType="DataGridCell">
           <Setter Property="Foreground" Value="Black" />
           <Style.Triggers>
               <Trigger Property="IsSelected" Value="True">
                   <Setter Property="Background" Value="{x:Null}" />
                   <Setter Property="BorderBrush" Value="{x:Null}" />
               </Trigger>
           </Style.Triggers>
       </Style>
   </DataGrid.CellStyle>
</DataGrid>

【讨论】:

  • 除了前景色变白且无法再看到内容外,其他都有效
猜你喜欢
  • 2011-11-20
  • 1970-01-01
  • 2011-01-15
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 2010-09-09
相关资源
最近更新 更多