.net WPF工具栏中溢出按钮的颜色

.net WPF工具栏中溢出按钮的颜色,.net,wpf,button,overflow,toolbar,.net,Wpf,Button,Overflow,Toolbar,有个问题。当我更改WPF工具栏的背景色时,右角的溢出按钮不会更改颜色。如何修复它 例如: 不幸的是,溢出按钮有一个固定的背景。更准确地说,它在默认模板中设置为静态值。看看或者如果你想得到它们的副本。或 在模板中,您将看到一个ToggleButton,用于显示/隐藏溢出面板。这是一个改变,有你正在寻找的效果 因此,您的问题的答案是,您需要在XAML中包含工具栏的完整样式,并将按钮的背景更改为与工具栏的其余部分相同。不幸的是,溢出按钮的背景是固定的。更准确地说,它在默认模板中设置为静态值。看看或者如

有个问题。当我更改WPF工具栏的背景色时,右角的溢出按钮不会更改颜色。如何修复它

例如:
不幸的是,溢出按钮有一个固定的背景。更准确地说,它在默认模板中设置为静态值。看看或者如果你想得到它们的副本。或

在模板中,您将看到一个ToggleButton,用于显示/隐藏溢出面板。这是一个改变,有你正在寻找的效果


因此,您的问题的答案是,您需要在XAML中包含工具栏的完整样式,并将按钮的背景更改为与工具栏的其余部分相同。

不幸的是,溢出按钮的背景是固定的。更准确地说,它在默认模板中设置为静态值。看看或者如果你想得到它们的副本。或

在模板中,您将看到一个ToggleButton,用于显示/隐藏溢出面板。这是一个改变,有你正在寻找的效果


因此,您的问题的答案是,您需要在XAML中包含工具栏的完整样式,并将按钮的背景更改为与工具栏的其余部分相同。

我遇到了与上述相同的问题。我的解决方案如下:

using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace WPF.Controls
{
    public class ToolBar : System.Windows.Controls.ToolBar
    {
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var overflowPanel = base.GetTemplateChild("PART_ToolBarOverflowPanel") as ToolBarOverflowPanel;
            if (overflowPanel != null)
            {
                overflowPanel.Background = OverflowPanelBackground ?? Background;
                overflowPanel.Margin = new Thickness(0);
            }
        }

        public Brush OverflowPanelBackground
        {
            get;
            set;
        }
    }
}
XAML样本:

<Window
    x:Class="WPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:WPF.Controls">

<ToolBarTray Background="White">
    <wpf:ToolBar Background="Pink" OverflowPanelBackground="Peru" Band="1" BandIndex="1" Width="50">
        <Button Content="Cut" />
        <Button Content="Copy" />
        <Button Content="Paste" />
    </wpf:ToolBar>
    <wpf:ToolBar Background="Aqua" Band="2" BandIndex="1" Width="70">
        <Button Content="Undo" />
        <Button Content="Redo" />
    </wpf:ToolBar>
    <wpf:ToolBar OverflowPanelBackground="Yellow" Band="2" BandIndex="2" Width="100">
        <Button Content="Paint"/>
        <Button Content="Spell"/>
        <Separator/>
        <Button Content="Save"/>
        <Button Content="Open"/>
    </wpf:ToolBar>
</ToolBarTray>

</Window>

我遇到了与上述问题相同的问题。我的解决方案如下:

using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace WPF.Controls
{
    public class ToolBar : System.Windows.Controls.ToolBar
    {
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var overflowPanel = base.GetTemplateChild("PART_ToolBarOverflowPanel") as ToolBarOverflowPanel;
            if (overflowPanel != null)
            {
                overflowPanel.Background = OverflowPanelBackground ?? Background;
                overflowPanel.Margin = new Thickness(0);
            }
        }

        public Brush OverflowPanelBackground
        {
            get;
            set;
        }
    }
}
XAML样本:

<Window
    x:Class="WPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:WPF.Controls">

<ToolBarTray Background="White">
    <wpf:ToolBar Background="Pink" OverflowPanelBackground="Peru" Band="1" BandIndex="1" Width="50">
        <Button Content="Cut" />
        <Button Content="Copy" />
        <Button Content="Paste" />
    </wpf:ToolBar>
    <wpf:ToolBar Background="Aqua" Band="2" BandIndex="1" Width="70">
        <Button Content="Undo" />
        <Button Content="Redo" />
    </wpf:ToolBar>
    <wpf:ToolBar OverflowPanelBackground="Yellow" Band="2" BandIndex="2" Width="100">
        <Button Content="Paint"/>
        <Button Content="Spell"/>
        <Separator/>
        <Button Content="Save"/>
        <Button Content="Open"/>
    </wpf:ToolBar>
</ToolBarTray>

</Window>

亚历克斯的回答很好。修改OverflowButton和OverflowPanel颜色的另一种方法是在加载的事件中修改它们

XAML


名称(OverflowGrid、OverflowButton和PART_工具栏OverflowPanel)可以在默认控件模板中找到,该模板可以从WPF的GitHub页面下载。

Alex的答案很好。修改OverflowButton和OverflowPanel颜色的另一种方法是在加载的事件中修改它们

XAML


名称(OverflowGrid、OverflowButton和PART_工具栏OverflowPanel)可以在默认控件模板中找到,该模板可以从WPF的GitHub页面下载。

我是WPF的新手。安东·格拉德琴科,你能把你是怎么做到的吗?几行代码可以更好地快速入门。谢谢我是WPF的新手。安东·格拉德琴科,你能把你是怎么做到的吗?几行代码可以更好地快速入门。谢谢它工作了,溢出区域现在有了新的背景。溢出按钮仍然是难看的淡蓝色。我想我仍然需要改变整个模板。它工作了,溢出区域现在有了新的背景。溢出按钮仍然是难看的淡蓝色。我想我还是要改变整个模板。