如何燮preSS DataGrid单元格选区边界?选区、边界、单元格、preSS

2023-09-03 13:33:16 作者:熬夜等死

我已经试过这里Disable在FullRow选择模式的DataGrid当前单元格边框,但它不会做的事情完全。当您选择使用鼠标禁用单元格边框选择,但做选择,在使用键盘还是有虚线的单元格边框。有什么建议?

I've tried setting border style as suggested here Disable DataGrid current cell border in FullRow selection mode, but it doesn't do the thing fully. Is disables cell border selection when you select using a mouse, but there is still a dashed cell border when making selection using keyboard. Any suggestions?

推荐答案

您看到的虚线框是细胞的 FocusedVisualStyle

the dashed box you see is the cell's FocusedVisualStyle

您需要重写,以便它是空白。

you need to override it so that it is blank.

2选择这里(其中一人必须是正确的,但因为我没有时间去尝试,我不知道是哪个)

2 options here (one of them has to be the right one but as I didn't have time to try, I don't know which)

的visualStyle直接设置单元格

这意味着你必须通过 CellStyle 属性来设置它:

this means you have to set it through the CellStyle property:

<DataGrid.CellStyle>
   <Style TargetType="DataGridCell">
      <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
   </Style>
</DataGrid.CellStyle>

或者如果你想遵守MS的模板准则:

or if you want to comply with MS's templating guidelines:

<DataGrid.Resources>

    <!--CellFocusVisual-->
    <Style x:Key="CellFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border>
                        <Rectangle StrokeThickness="0" Stroke="#00000000" StrokeDashArray="1 2"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</DataGrid.Resources>

<DataGrid.CellStyle>
   <Style TargetType="DataGridCell">
      <Setter Property="FocusVisualStyle" Value="{StaticResource CellFocusVisual}"/>
   </Style>
</DataGrid.CellStyle>

(这种方式,你可以看到它是如何做)

(this way, you can see how it is done)

其他选项:它是通过完成 ElementStyle EditingElementStyle

这更多的是一种Hasle城的出现,因为 ElementStyle EditingElementStyle 在列的定义,至极的手段你必须编辑每列的 ElementStyle EditingElementStyle

this is more of a hasle there, because the ElementStyle and EditingElementStyle are defined on the Column, wich means you have to edit each column's ElementStyle and EditingElementStyle.

但基本上,这是同样的事情:在设置FocusVisualStyle为空或风格通过 ElementStyle 和/或 EditingElementStyle上面定义每列

but basically, this is the same thing: you set up the FocusVisualStyle to null or the style defined above through the ElementStyle and/or EditingElementStyle on each Column