【问题标题】:Default blue color when hovering over things such as ComboBoxs [duplicate]将鼠标悬停在诸如组合框之类的东西上时的默认蓝色 [重复]
【发布时间】:2012-10-03 20:23:20
【问题描述】:

可能重复:
wpf set ComboBox selected item highlight color

首先抱歉,如果这个问题已经得到解答,我整个晚上都在浏览 Google 试图找到解决方案,甚至不确定我搜索的内容是否正确。

我的问题是,当我单击/悬停在组合框/按钮等上时,它会显示默认的系统蓝色,我希望能够将其删除或将其更改为在组合框中的选择上悬停时使用的灰色。这是一个 WPF 项目,我添加了一些图片来显示问题所在。 我尝试了几种不同的方法,但都没有运气。我希望我忽略了一个简单的设置。

【问题讨论】:

  • 感到困惑的是,您想要更改控件中选定项目的颜色,当它被悬停时,或者当它被悬停在控件上时。两种不同的动物。
  • @TonyHopkinson 知道青春是获得系统颜色的蓝色组合框
  • 这是您需要的吗? stackoverflow.com/questions/1278144/…

标签: c# wpf combobox default


【解决方案1】:

在高级别您需要style your ComboBox

这是一篇很好的 blog 帖子,介绍了如何让它看起来完全不同。

要更改默认颜色,您需要这种类型的 xmal(取自 blog

 <ControlTemplate x:Key="CustomToggleButton" TargetType="ToggleButton">
    <Grid>
        <Border Name="Border" />
        <Border Name="SmallBorder" />
        <Path Name="Arrow" />
    </Grid>
</ControlTemplate>

<Style TargetType="{x:Type ComboBoxItem}">
    <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True" />
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                <Border>
                    <ContentPresenter />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type ComboBox}">
    <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True" />
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <ToggleButton Template="{StaticResource CustomToggleButton}" />
                    <ContentPresenter />
                    <TextBox />
                    <Popup>
                        <Grid>
                            <Border>
                                <ScrollViewer>
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </Border>
                        </Grid>
                    </Popup>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 2021-03-12
    • 2012-10-10
    相关资源
    最近更新 更多