【发布时间】:2020-03-05 20:51:35
【问题描述】:
我为WPF DataGrid 创建了一个自定义样式。
一件事是在每个单元格上添加一个边距。
工作正常,但单击边距时无法选择行。
我不知道如何解决此问题。
<DataGrid ItemsSource="{Binding Items}">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<!-- Here is the margin for every cell -->
<ContentPresenter Margin="20"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="BorderThickness" Value="0 1 0 1"/>
<Setter Property="BorderBrush" Value="{x:Null}"/>
<Style.Triggers>
<!-- mouseover works fine, even for the margin -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Orange"/>
</Trigger>
<!-- this gets not set when you click on the margin in the cell, so you think when the row highlightes you also can select it, but you cant -->
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
</DataGrid>
【问题讨论】:
标签: wpf xaml datagrid styles margin