简体   繁体   English

Windows 10 WPF Xaml ListView项目样式与Windows 7不匹配

[英]Windows 10 WPF Xaml ListView Item Styles Not Matching Windows 7

I have a WPF app that needs to support Win 7 and 10. I can style ListView items ok and get the results I want, no mouseover or selection color at all ever, on Windows 7. On Windows 10, it still highlights blue with mouseover or when touch scrolling. 我有一个WPF应用程序,需要支持Win 7和10。我可以在Windows 7上设置ListView项目的样式,并获得所需的结果,完全没有鼠标悬停或选择颜色,在Windows 7上。在Windows 10上,鼠标悬停仍然突出显示蓝色或触摸滚动时。 Style and screenshots below. 下面的样式和屏幕截图。 Everything I find Googling this says I'm doing it right, but the highlight remains. 我在Google搜索中发现的所有内容都表示我做得对,但重点仍然是。 Assuming it is something slightly different for 10 that isn't popping up for me. 假设10点有些不同,但对我而言却并不如此。

Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                         Color="Transparent"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                         Color="Transparent" />
    </Style.Resources>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
        </Trigger>
    </Style.Triggers>
</Style>

Windows 7 Windows 7的 在此处输入图片说明

Windows 10 Windows 10 在此处输入图片说明

The OS level things changed for 8 and 10. Try something like this instead: 操作系统级别在8和10时发生了变化。请尝试以下类似方法:

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
            <Border x:Name="Bd"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Padding="{TemplateBinding Padding}"
                    SnapsToDevicePixels="True">
                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Content="{TemplateBinding Content}"
                                    ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Border>
            <ControlTemplate.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsMouseOver" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter TargetName="Bd" Property="Background" Value="Transparent" />
                    <Setter TargetName="Bd" Property="BorderBrush" Value="Transparent" />
                </MultiTrigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="Selector.IsSelectionActive" Value="False" />
                        <Condition Property="IsSelected" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter TargetName="Bd" Property="Background" Value="Transparent" />
                    <Setter TargetName="Bd" Property="BorderBrush" Value="Transparent" />
                </MultiTrigger>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="Selector.IsSelectionActive" Value="True" />
                        <Condition Property="IsSelected" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter TargetName="Bd" Property="Background" Value="Transparent" />
                    <Setter TargetName="Bd" Property="BorderBrush" Value="Transparent" />
                </MultiTrigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

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

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