简体   繁体   English

WPF Datagrid单元格中“突出显示文本”的背景颜色

[英]Background color of 'Highlight Text' in WPF Datagrid cell

This is not the simple "IsSelected" background color of a datagrid row. 这不是数据网格行的简单“ IsSelected”背景色。 What I am referring to is when I am in a datagrid, that has editable data, I click in a given cell and have any text (for example an address), if I select part of the text, the HIGHLIGHT coloring is what I want to change... I assume it would be part of the DataGridCell styling, but not sure where. 我指的是当我在一个具有可编辑数据的数据网格中时,我单击一个给定的单元格并具有任何文本(例如地址),如果我选择了文本的一部分,则需要使用HIGHLIGHT着色进行更改...我认为这将是DataGridCell样式的一部分,但不确定在哪里。

You are looking for the TextBoxBase.SelectionBrush Property . 您正在寻找TextBoxBase.SelectionBrush属性 From the linked page on MSDN: 从MSDN上的链接页面:

Gets or sets the brush that highlights selected text. 获取或设置突出显示所选文本的画笔。

<TextBox SelectionBrush="Red" SelectionOpacity="0.5" 
    Foreground="Blue" CaretBrush="Blue">  
    This is some text.
</TextBox>

在此处输入图片说明


UPDATE >>> 更新>>>

You can apply this property in a Style that is applied to the DataGridTextColumn.EditingElementStyle property, like this: 您可以在应用于DataGridTextColumn.EditingElementStyle属性的Style中应用此属性,如下所示:

<DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Name}">
            <DataGridTextColumn.EditingElementStyle>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="SelectionBrush" Value="Red" />
                </Style>
            </DataGridTextColumn.EditingElementStyle>
        </DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM