Mic*_*eyn 48 wpf wpfdatagrid wpf-4.0
我在行选择模式中使用DataGrid(即SelectionUnit="FullRow"
).我只想删除当用户突出显示一行时为当前单元格放置的边框,以便进行真正的全行选择(并且不选择单元格级别).我不介意网格保持当前单元格的概念,我只想删除那个讨厌的当前单元格边界,可能是通过改变当前单元格的样式.最简单的方法是什么?
Fre*_*lad 99
您可以将BorderThickness
for 设置为DataGridCell
0
<DataGrid ...
SelectionUnit="FullRow">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
<!-- Update from comments.
Remove the focus indication for the selected cell -->
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</DataGrid.CellStyle>
<!-- ... -->
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
在这里看到另一个接近的答案,但它并没有摆脱Focus矩形.这是如何消除所有边界.
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</DataGrid.Resources>
Run Code Online (Sandbox Code Playgroud)
另外,从技术上来说,那些单元格仍然可以获得焦点(你只是看不到它),为了使tab键前进到下一行而不是下一个单元格,我根据上面的内容定义了一个单元格样式,但也添加了以下...
<DataGrid.Resources>
<Style x:Key="NoFocusDataGridCell" TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="Focusable" Value="False" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="IsHitTestVisible" Value="False" />
</Style>
</DataGrid.Resources>
Run Code Online (Sandbox Code Playgroud)
...然后我将其应用于除第一列定义之外的所有内容.这样Tab键进入下一行,而不是下一行.
然而,回到边界.如果你想隐藏它们但仍希望它们成为间距原因的布局的一部分,请将上面的内容更改为...
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</DataGrid.Resources>
Run Code Online (Sandbox Code Playgroud)
请享用!:)
小智 6
<Style x:Key="DataGrid" TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" />
</Style>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
36271 次 |
最近记录: |