简体   繁体   English

如何更改WPF ListView上项目焦点矩形的颜色? (不是项目突出显示的颜色)

[英]How do I change the color of the item focus rectangle on a WPF ListView? (not the item highlight color)

How do I change the color of the item focus rectangle on a WPF ListView? 如何更改WPF ListView上项目焦点矩形的颜色?

It's the color of the focus rectangle I mean to change, not the color of the selected item (which is green). 这是我要更改的焦点矩形的颜色,而不是所选项目的颜色(绿色)。

See image: 见图片: 在此处输入图片说明

To change the appearance of the focus visual of an item in the ListView , you will have to manipulate the FocusVisualStyle that is part of the ItemContainerStyle used by the ListView . 若要更改ListView中某个项目的焦点视觉外观,您将必须操纵FocusVisualStyle ,它是ListView使用的ItemContainerStyle一部分。

To illustrate, here is a simple example that turns the focus visual into a red dashed (dotted line) rectangle: 为了说明这一点,这是一个简单的示例,将焦点视觉变为红色的虚线(虚线)矩形:

<ListView ...>
    <ListView.ItemContainerStyle>

        <!-- This is the style used by the item container of this ListView -->
        <Style TargetType="ListViewItem">
            <Setter Property="FocusVisualStyle">
                <Setter.Value>

                    <!-- This is the style for the focus visual -->
                    <Style>
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Rectangle SnapsToDevicePixels="true"
                                               Stroke="Red"
                                               StrokeThickness="1"
                                               StrokeDashArray="1 2"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                </Setter.Value>
            </Setter>
        </Style>

    </ListView.ItemContainerStyle>
</ListView>

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

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