Skip to content

Commit 5baa036

Browse files
KebooCopilot
andcommitted
Fix ToolBar overflow button background not inheriting from ToolBar
Change the overflow button styles to bind their Background to the ancestor ToolBar's Background instead of hardcoding the theme resource. This ensures the overflow button matches when a custom Background is set on the ToolBar. Changes: - Both vertical and horizontal overflow button styles now use a RelativeSource binding to the parent ToolBar's Background - Overflow popup border uses TemplateBinding to inherit Background - Removed redundant Background reset in the vertical orientation trigger Fixes #3694 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 17ed69e commit 5baa036

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ToolBar.xaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ResourceDictionary.MergedDictionaries>
1818

1919
<Style x:Key="MaterialDesignToolBarVerticalOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
20-
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.ToolBar.Background}" />
20+
<Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType=ToolBar}}" />
2121
<Setter Property="MinHeight" Value="0" />
2222
<Setter Property="MinWidth" Value="0" />
2323
<Setter Property="Template">
@@ -55,7 +55,7 @@
5555
</Style>
5656

5757
<Style x:Key="MaterialDesignToolBarHorizontalOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
58-
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.ToolBar.Background}" />
58+
<Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType=ToolBar}}" />
5959
<Setter Property="MinHeight" Value="0" />
6060
<Setter Property="MinWidth" Value="0" />
6161
<Setter Property="Template">
@@ -187,7 +187,7 @@
187187
CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
188188
<Border x:Name="ToolBarSubMenuBorder"
189189
Margin="1"
190-
Background="{DynamicResource MaterialDesign.Brush.ToolBar.Background}"
190+
Background="{TemplateBinding Background}"
191191
BorderBrush="{DynamicResource MaterialDesign.Brush.ToolBar.Overflow.Border}"
192192
BorderThickness="1"
193193
CornerRadius="2"
@@ -246,7 +246,6 @@
246246
<Setter TargetName="ToolBarSubMenuBorder" Property="Margin" Value="5,5,5,5" />
247247
</Trigger>
248248
<Trigger Property="Orientation" Value="Vertical">
249-
<Setter Property="Background" Value="{DynamicResource MaterialDesign.Brush.ToolBar.Background}" />
250249
<Setter TargetName="Grid" Property="Margin" Value="1,3,1,1" />
251250
<Setter TargetName="MainPanelBorder" Property="Margin" Value="0,0,0,11" />
252251
<Setter TargetName="OverflowButton" Property="Style" Value="{StaticResource MaterialDesignToolBarVerticalOverflowButtonStyle}" />

tests/MaterialDesignThemes.UITests/WPF/ToolBars/ToolBarTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using System.Windows.Media;
23

34

45
namespace MaterialDesignThemes.UITests.WPF.ToolBars;
@@ -30,4 +31,28 @@ public async Task ToolBar_OverflowGrid_RespectsOrientation(Orientation orientati
3031

3132
recorder.Success();
3233
}
34+
35+
[Description("Issue 3694")]
36+
[Test]
37+
public async Task ToolBar_OverflowButton_InheritsCustomBackground()
38+
{
39+
await using var recorder = new TestRecorder(App);
40+
41+
//Arrange
42+
var toolBarTray = await LoadXaml<ToolBarTray>(@"
43+
<ToolBarTray DockPanel.Dock=""Top"">
44+
<ToolBar Style=""{StaticResource MaterialDesignToolBar}"" Background=""Fuchsia"" OverflowMode=""Always"">
45+
<Button Content=""{materialDesign:PackIcon Kind=File}""/>
46+
</ToolBar>
47+
</ToolBarTray>");
48+
var overflowButton = await toolBarTray.GetElement<ToggleButton>("OverflowButton");
49+
50+
//Act
51+
Color? overflowBackground = await overflowButton.GetBackgroundColor();
52+
53+
//Assert
54+
await Assert.That(overflowBackground).IsEqualTo(Colors.Fuchsia);
55+
56+
recorder.Success();
57+
}
3358
}

0 commit comments

Comments
 (0)