Skip to content

Commit 007eed3

Browse files
TabControl should honor TabItem.ContentTemplate (and others) (#3278)
* Add failing UI test * Add fix which makes test run green The test only asserts on the ContentTemplate property. I did not bother checking the others.
1 parent 6378716 commit 007eed3

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

MaterialDesignThemes.UITests/WPF/TabControls/TabControlTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,38 @@ public async Task TabItem_ShouldKeepDataContext_WhenContextMenuOpens(string hori
121121

122122
recorder.Success();
123123
}
124+
125+
[Fact]
126+
[Description("Issue 3271")]
127+
public async Task TabControl_ShouldRespectSelectedContentTemplate_WhenSetDirectlyOnTabItem()
128+
{
129+
await using var recorder = new TestRecorder(App);
130+
131+
//Arrange
132+
IVisualElement<TabControl> tabControl = await LoadXaml<TabControl>("""
133+
<TabControl materialDesign:ColorZoneAssist.Mode="PrimaryMid"
134+
Style="{StaticResource MaterialDesignFilledTabControl}">
135+
<TabControl.Resources>
136+
<DataTemplate x:Key="CustomContentTemplate">
137+
<Border Background="Fuchsia" Padding="10" Margin="10" CornerRadius="10">
138+
<TextBlock Text="{Binding .}" />
139+
</Border>
140+
</DataTemplate>
141+
</TabControl.Resources>
142+
<TabItem Content="Tab content string" ContentTemplate="{StaticResource CustomContentTemplate}" />
143+
</TabControl>
144+
""");
145+
146+
IVisualElement<Border> selectedContentBorder = await tabControl.GetElement<Border>("PART_BorderSelectedContent");
147+
148+
//Act
149+
var customContentBorder = await selectedContentBorder.GetElement<Border>("/Border");
150+
IVisualElement<TextBlock> customContent = await customContentBorder.GetElement<TextBlock>(@"/TextBlock");
151+
152+
//Assert
153+
Assert.Equal(Colors.Fuchsia, await customContentBorder.GetBackgroundColor());
154+
Assert.Equal("Tab content string", await customContent.GetText());
155+
156+
recorder.Success();
157+
}
124158
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TabControl.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
<ContentPresenter x:Name="PART_SelectedContentHost"
7373
Margin="{TemplateBinding Padding}"
7474
ContentSource="SelectedContent"
75-
ContentStringFormat="{TemplateBinding ContentStringFormat}"
76-
ContentTemplate="{TemplateBinding ContentTemplate}"
77-
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
75+
ContentStringFormat="{TemplateBinding SelectedContentStringFormat}"
76+
ContentTemplate="{TemplateBinding SelectedContentTemplate}"
77+
ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}"
7878
Focusable="False"
7979
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
8080
</Border>

0 commit comments

Comments
 (0)