WPF 设置 ComboBox 向下箭头按钮的颜色

发布于 2024-09-28 08:24:57 字数 1289 浏览 7 评论 0原文

我正在尝试设计 WPF ComboBox 的样式,以便它与我们下一个项目正在考虑的黑色主题相匹配。

我的问题是,如果组合框的背景是黑色,则按钮不会显示(因为它也是黑色的)。

由于某种原因,我无法找到有关如何更改其颜色的任何信息。

以下 XAML 是我当前用于将 ComboBox 样式设置为黑色的 XAML:

<ComboBox Name="myComboBox" VerticalAlignment="Top" Width="120"  HorizontalAlignment="Right">
    <ComboBox.Resources>
        <LinearGradientBrush  x:Key="{x:Static SystemColors.HighlightBrushKey}"  StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#FFCBCBCB" Offset="0.0"/>
            <GradientStop Color="#FF7C7C7C" Offset="0.3"/>
            <GradientStop Color="black" Offset="1"></GradientStop>
        </LinearGradientBrush>
    </ComboBox.Resources>
    <ComboBox.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
            <GradientStop Color="white" Offset="0"/>
            <GradientStop Color="black" Offset="1"/>
        </LinearGradientBrush>
    </ComboBox.Background>
    <ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
    <ComboBoxItem  Name="cbi2">Item2</ComboBoxItem>
    <ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</ComboBox>

对于该主题的任何帮助将不胜感激。

谢谢,

-弗林尼

I am trying to style a WPF ComboBox so that it matches a black-theme that is being considered for our next project.

My problem is that if the ComboBox's background is black, the button doesn't show up (since it is also black).

For some reason I have not been able to find any information about how to change it's colour.

The following XAML is that I currently have for styling the ComboBox in black:

<ComboBox Name="myComboBox" VerticalAlignment="Top" Width="120"  HorizontalAlignment="Right">
    <ComboBox.Resources>
        <LinearGradientBrush  x:Key="{x:Static SystemColors.HighlightBrushKey}"  StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#FFCBCBCB" Offset="0.0"/>
            <GradientStop Color="#FF7C7C7C" Offset="0.3"/>
            <GradientStop Color="black" Offset="1"></GradientStop>
        </LinearGradientBrush>
    </ComboBox.Resources>
    <ComboBox.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
            <GradientStop Color="white" Offset="0"/>
            <GradientStop Color="black" Offset="1"/>
        </LinearGradientBrush>
    </ComboBox.Background>
    <ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
    <ComboBoxItem  Name="cbi2">Item2</ComboBoxItem>
    <ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</ComboBox>

Any help on the topic would be greatly appreciated.

Thanks,

-Frinny

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-10-05 08:24:57

您将必须修改 ComboBox 的 ControlTemplate。

控件本身乍一看令人惊讶,但仔细想想却并不复杂。我建议进入 Blend(如果有的话)并提取 ControlTemplate。否则,您可以使用 XAMLWriter 获取 ComboBox 的 XAML。

这个不幸命名的页面(我不认为这真的是“儿童的” Stuff”,你呢?)有一个做这两件事的例子。

You are going to have to modify the ControlTemplate for the ComboBox.

The control itself is surprisingly-at-first-but-not-when-you-think-about-it complex. I would recommend going into Blend (if you have it) and extracting the ControlTemplate. Otherwise, you can get the XAML for a ComboBox using XAMLWriter.

This unfortunately named page (I don't think this is really "Kid's Stuff", do you?) has an example of doing both of these things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文