.net 4.5 下的列表/组合框背景和选定颜色

List/Combo Box Background And Selected Colours Under .net 4.5(.net 4.5 下的列表/组合框背景和选定颜色)
本文介绍了.net 4.5 下的列表/组合框背景和选定颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对 .net 4 框架的应用程序,它在 Windows 7 及更低版本上运行良好.
如果该应用程序现在安装在 Windows 8 中(运行 .net 4.5 但仍以 .net 4 为目标),它会为列表框或组合框中的选定项目显示蓝色背景,并为焦点项目显示白色背景.有没有办法去掉这个?
我在我的 XAML 中使用以下内容来设置有问题的样式,这似乎解决了 Windows 8 之前的问题.

I have an application that's been running happily on windows 7 and below targeting the .net 4 framework.
If the application is now installed in windows 8 (Running .net 4.5 but still targeting .net 4) it shows a blue background for a selected item in a listbox or combobox and a white background for a focused item. Is there anyway to remove this?
I'm using the following in my XAML to set the style in question which seemed to resolve the issue before windows 8.

<ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                    <Style.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                    </Style.Resources>
                </Style>
            </ListBox.ItemContainerStyle>

推荐答案

我忘了回过头来说我是如何解决这个问题的......原来你需要做的就是创建一个空白的 Item Container Style 并将其分配给您的列表框/组合框等......您可以使用它以及保留您可能正在使用的当前样式,例如 ListBox Style="{StaticResource CurrentStyle}" ItemContainerStyle="{StaticResource BlankListBoxContainerStyle}"/> 其中 BlankListBoxContainerStyle 会是什么喜欢.....

I forgot to come back with how I solved this.... Turns out that all you need to do it create a blank Item Container Style and assign it to your listbox/combobox etc.... You can use this as well as keeping the current style you may be using such as ListBox Style="{StaticResource CurrentStyle}" ItemContainerStyle="{StaticResource BlankListBoxContainerStyle}" /> Where BlankListBoxContainerStyle would be something like.....

<Style x:Key="BlankListBoxContainerStyle" TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="FocusVisualStyle"
            Value="{x:Null}"/>
</Style>

这篇关于.net 4.5 下的列表/组合框背景和选定颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)