2010-05-04 85 views

回答

4

溢流按钮不幸具有固定的背景。更确切地说,它在默认模板中设置为静态值。如果您想获得它们的副本,请参阅this MSDN forum threadMSDN。或This tool from Chris Sells

在模板中,您将看到一个用于显示/隐藏溢出面板的ToggleButton。这是需要改变才能产生效果的那个人。

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

+0

感谢您的回答! – antongladchenko 2010-05-05 06:14:26

1

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

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> 
+0

它的工作原理,溢流区现在有了新的背景。溢出按钮仍然是难看的婴儿蓝色。我想我仍然需要更改整个模板。 – 2017-04-18 12:00:23

相关问题