In a nested WPF ToolBarPanel-ToolBar-Menu we want to get rid of the grip handle to the left and the overflow area to the right. they are both grayed out, but we\'d like them
Rather than hiding the overflow button completely, I think it's better to show it only when necessary. This can be done by binding its Visibility
property to its IsEnabled
property:
private static void FixupToolBarOverflowArrow(ToolBar toolBar)
{
Action fixup = () =>
{
var overflowButton = toolBar.Template.FindName("OverflowButton", toolBar) as ButtonBase;
if (overflowButton != null)
{
overflowButton.SetBinding(
VisibilityProperty,
new Binding("IsEnabled")
{
RelativeSource = RelativeSource.Self,
Converter = new BooleanToVisibilityConverter()
});
}
};
if (toolBar.IsLoaded)
{
fixup();
}
else
{
RoutedEventHandler handler = null;
handler = (sender, e) =>
{
fixup();
toolBar.Loaded -= handler;
};
toolBar.Loaded += handler;
}
}
(the same thing can be done in XAML by redefining the template)