.net 4.5 下的列表/组合框背景和选定颜色 [英] List/Combo Box Background And Selected Colours Under .net 4.5

查看:28
本文介绍了.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 下的列表/组合框背景和选定颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆