Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf XAML ListView取消选择的背景色不工作_Wpf_Xaml - Fatal编程技术网

Wpf XAML ListView取消选择的背景色不工作

Wpf XAML ListView取消选择的背景色不工作,wpf,xaml,Wpf,Xaml,我在listview中使用了以下代码: <Style TargetType="ListViewItem"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/> <SolidColorBrush x:Key="{x:Static SystemColors.Control

我在listview中使用了以下代码:

<Style TargetType="ListViewItem">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red"/>
    </Style.Resources>
</Style>

但是,红色不起作用。它仍然是默认的灰色

编辑:

我也试过:

 <Style x:Key="MyListView" TargetType="{x:Type ListView}">
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="ListBoxItem">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Green"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Red"/>
                </Style.Resources>
            </Style>
        </Setter.Value>
    </Setter>
</Style>


同样的结果。

您使用什么代码/xaml分配这些资源?简单地将它们定义为资源不会将它们应用于任何UI元素。。。如果我们想帮助您,请分享更多代码/标记。我应该仔细看看您的XAML。您不希望这样分配密钥。你是WPF的新手吗?如果是这样,我认为你问错了问题。这里有很多帮助,这些人都很出色……但是我认为你缺乏一些基于你的问题/例子的基本知识。你只是覆盖了默认的系统颜色。我想你不想那样。您更可能希望为listView创建样式/模板。看看这个mh。。。我发现这是一个解决办法,但我想我理解错了。我想为我的listview设置一个样式,用于设置所选项目的背景色。此外,如果没有焦点,请在此处找到: