J'ai eu le même problème que vous avez décrit ci-dessus. Ma solution est la suivante:
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;
}
}
}
échantillon 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>
Je suis un débutant dans WPF. Pouvez-vous poster un code sur la façon dont vous l'avez fait, antongladchenko? Quelques lignes de code seraient mieux pour obtenir un démarrage rapide. Merci! – GRF