【问题标题】:Why isnt my Background color working in a ComboBox为什么我的背景颜色不能在 ComboBox 中工作
【发布时间】:2016-12-25 13:29:13
【问题描述】:

我的组合框唯一不起作用的部分是背景颜色。我希望整个东西都是黄色的。但是折叠的部分仍然只是灰色的。

<ComboBox Height="25" Width="125" Background="Yellow">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Background" Value="Yellow"/>
            <Setter Property="BorderBrush" Value="Yellow"/>
        </Style>
    </ComboBox.ItemContainerStyle>
    <ComboBoxItem Content="One"/>
    <ComboBoxItem Content="Two"/>
    <ComboBoxItem Content="Three"/>
</ComboBox>

【问题讨论】:

标签: c# wpf combobox


【解决方案1】:

也许这可以帮助你:

<ComboBox Height="25" Width="125" Background="Yellow"
          Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Background" Value="Yellow"/>
            <Setter Property="BorderBrush" Value="Yellow"/>
        </Style>
    </ComboBox.ItemContainerStyle>
    <ComboBoxItem Content="One"/>
    <ComboBoxItem Content="Two"/>
    <ComboBoxItem Content="Three"/>
</ComboBox>

【讨论】:

    【解决方案2】:

    在 windows 7 中使用 wpf 时,您的代码应该可以正常工作。但是,如果您运行的是 windows 8 或更高版本,则可能不适用。

    这个https://blog.magnusmontin.net/2014/04/30/changing-the-background-colour-of-a-combobox-in-wpf-on-windows-8/ 可能会帮助你实现你想要的。

    作者对此给出了很好的解释。

    【讨论】:

    • 那篇文章准确地描述了我的问题。谢谢。
    • 欢迎吉姆!或许我们俩都得感谢文章作者的精彩解释;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    相关资源
    最近更新 更多