C# 防止矩形样式应用于DataGrid

C# 防止矩形样式应用于DataGrid,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,我在我的app.config中设置了样式,我想给我在程序中使用的每个矩形上色。它很好很简单,看起来像这样 <Style TargetType="Rectangle"> <Setter Property="Fill" Value="LightBlue"/> </Style> DataGridCells使用FocusVisualStyle,它的可视树中有矩形。这些矩形从默认矩形样式中获取Fill笔刷。如果更改焦点visualstyle,则在键盘选择上可以

我在我的
app.config
中设置了
样式
,我想给我在程序中使用的每个
矩形
上色。它很好很简单,看起来像这样

<Style TargetType="Rectangle">
    <Setter Property="Fill" Value="LightBlue"/>
</Style>

DataGridCells
使用
FocusVisualStyle
,它的可视树中有矩形。这些矩形从默认矩形样式中获取
Fill
笔刷。如果更改
焦点visualstyle
,则在键盘选择上可以看到单元格

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


其他信息:我对
按钮和使用
选项卡的选择有同样的问题。嗨,我已经更新了我的问题。您的修复确实可以保留文本,但是它(正如我所期望的)删除了我希望应用于
DataGridCell
的样式。有没有一种方法可以同时做到这两个方面呢?为提出一条旧的思路而道歉。。但是现在,当我在做一些事情,例如
dataGrid.Focus()
时,整个
dataGrid
被填充成浅蓝色。我再次假设在
DataGrid
中使用了矩形,不知何故,有没有办法防止这种情况发生?正如您在回答中所述,我在切换
按钮时也遇到了这个问题。您是如何绕过
按钮
问题的?@CBreeze看起来又是他们的
焦点视觉样式
,它基本上是一个矩形,但没有默认的填充值。这篇文章可能会有帮助:
<DataGrid.CellStyle>
    <Style TargetType="{x:Type DataGridCell}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    </Style>
</DataGrid.CellStyle>
<Style TargetType="DataGridCell">
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="Orange" />
            <Setter Property="BorderBrush" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>