未验证 提交 007eed3c 编写于 作者: N Nicolai Henriksen 提交者: GitHub

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.
上级 6378716b
...@@ -121,4 +121,38 @@ public async Task TabItem_ShouldKeepDataContext_WhenContextMenuOpens(string hori ...@@ -121,4 +121,38 @@ public async Task TabItem_ShouldKeepDataContext_WhenContextMenuOpens(string hori
recorder.Success(); recorder.Success();
} }
[Fact]
[Description("Issue 3271")]
public async Task TabControl_ShouldRespectSelectedContentTemplate_WhenSetDirectlyOnTabItem()
{
await using var recorder = new TestRecorder(App);
//Arrange
IVisualElement<TabControl> tabControl = await LoadXaml<TabControl>("""
<TabControl materialDesign:ColorZoneAssist.Mode="PrimaryMid"
Style="{StaticResource MaterialDesignFilledTabControl}">
<TabControl.Resources>
<DataTemplate x:Key="CustomContentTemplate">
<Border Background="Fuchsia" Padding="10" Margin="10" CornerRadius="10">
<TextBlock Text="{Binding .}" />
</Border>
</DataTemplate>
</TabControl.Resources>
<TabItem Content="Tab content string" ContentTemplate="{StaticResource CustomContentTemplate}" />
</TabControl>
""");
IVisualElement<Border> selectedContentBorder = await tabControl.GetElement<Border>("PART_BorderSelectedContent");
//Act
var customContentBorder = await selectedContentBorder.GetElement<Border>("/Border");
IVisualElement<TextBlock> customContent = await customContentBorder.GetElement<TextBlock>(@"/TextBlock");
//Assert
Assert.Equal(Colors.Fuchsia, await customContentBorder.GetBackgroundColor());
Assert.Equal("Tab content string", await customContent.GetText());
recorder.Success();
}
} }
...@@ -72,9 +72,9 @@ ...@@ -72,9 +72,9 @@
<ContentPresenter x:Name="PART_SelectedContentHost" <ContentPresenter x:Name="PART_SelectedContentHost"
Margin="{TemplateBinding Padding}" Margin="{TemplateBinding Padding}"
ContentSource="SelectedContent" ContentSource="SelectedContent"
ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentStringFormat="{TemplateBinding SelectedContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding SelectedContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}"
Focusable="False" Focusable="False"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border> </Border>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册