feat: temporarily change ContentPresenter to Label. update pointerover/selected style.

This commit is contained in:
rabbitism 2022-12-13 12:04:49 +08:00
parent 9e2b51f1e2
commit 8c919dd25d
4 changed files with 67 additions and 64 deletions

View File

@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pages="using:Semi.Avalonia.Demo.Pages"
Title="Semi.Demo" d:DesignHeight="450"
d:DesignWidth="800" mc:Ignorable="d">
<TabControl TabStripPlacement="Left">
<TabControl Margin="8" TabStripPlacement="Left">
<TabItem Header="TextBlock">
<pages:TextBlockDemo />
</TabItem>

View File

@ -9,6 +9,9 @@
<TabItem Content="Hello 1" Header="Tab 1" />
<TabItem Content="Hello 2" Header="Tab 2" />
<TabItem Content="Hello 3" Header="Tab 3" />
<TabItem
Content="Hello 4" Header="Tab 4"
IsEnabled="False" />
</TabControl>
</Border>
<Border Theme="{StaticResource CardBorder}">
@ -16,6 +19,9 @@
<TabItem Content="Hello 1" Header="Tab 1" />
<TabItem Content="Hello 2" Header="Tab 2" />
<TabItem Content="Hello 3" Header="Tab 3" />
<TabItem
Content="Hello 4" Header="Tab 4"
IsEnabled="False" />
</TabControl>
</Border>
<Border Theme="{StaticResource CardBorder}">
@ -23,6 +29,9 @@
<TabItem Content="Hello 1" Header="Tab 1" />
<TabItem Content="Hello 2" Header="Tab 2" />
<TabItem Content="Hello 3" Header="Tab 3" />
<TabItem
Content="Hello 4" Header="Tab 4"
IsEnabled="False" />
</TabControl>
</Border>
<Border Theme="{StaticResource CardBorder}">
@ -30,6 +39,9 @@
<TabItem Content="Hello 1" Header="Tab 1" />
<TabItem Content="Hello 2" Header="Tab 2" />
<TabItem Content="Hello 3" Header="Tab 3" />
<TabItem
Content="Hello 4" Header="Tab 4"
IsEnabled="False" />
</TabControl>
</Border>
</StackPanel>

View File

@ -2,7 +2,7 @@
<!-- Theme: Card, Strip default is Strip -->
<Design.PreviewWith>
<StackPanel Margin="20">
<TabItem Foreground="Red" Header="Hello">
<TabItem Header="Hello">
<TextBlock Text="Content" />
</TabItem>
</StackPanel>
@ -24,7 +24,7 @@
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Panel>
<ContentPresenter
<Label
Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
@ -33,12 +33,12 @@
ContentTemplate="{TemplateBinding HeaderTemplate}"
FontFamily="{TemplateBinding FontFamily}"
FontWeight="{TemplateBinding FontWeight}"
TextElement.FontSize="30" />
Foreground="{TemplateBinding Foreground}" />
<Border
Name="PART_SelectedPipe"
Background="{DynamicResource TabItemLinePipeSelectedBackground}"
Background="{DynamicResource TabItemLinePipeBackground}"
CornerRadius="{DynamicResource ControlCornerRadius}"
IsVisible="False" />
IsVisible="True" UseLayoutRounding="False" />
</Panel>
</Border>
</ControlTemplate>
@ -46,33 +46,26 @@
<!-- Selected state -->
<!-- We don't use selector to PART_LayoutRoot, so developer can override selected item background with TabStripItem.Background -->
<Style Selector="^:selected">
<Setter Property="Foreground" Value="Blue" />
<Style Selector="^:selected /template/ Label#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource TabItemLineHeaderSelectedForeground}" />
<Setter Property="Label.FontWeight" Value="{DynamicResource TabItemSelectedFontWeight}" />
</Style>
<Style Selector="^:not(:selected)">
<Setter Property="Cursor" Value="Hand" />
<Style Selector="^:pointerover /template/ Label#PART_ContentPresenter">
<Setter Property="Label.Foreground" Value="{DynamicResource TabItemLineHeaderPointeroverForeground}" />
</Style>
<Style Selector="^:pointerover /template/ Border#PART_SelectedPipe">
<Setter Property="Border.Background" Value="{DynamicResource TabItemLinePipePointeroverBorderBrush}" />
</Style>
<Style Selector="^:pressed /template/ Border#PART_SelectedPipe">
<Setter Property="Border.Background" Value="{DynamicResource TabItemLinePipePressedBorderBrush}" />
</Style>
</Style>
<Style Selector="^:selected /template/ Border#PART_SelectedPipe">
<Setter Property="IsVisible" Value="True" />
</Style>
<!-- PointerOver state -->
<Style Selector="^:pointerover /template/ Border#PART_LayoutRoot">
<Setter Property="TextElement.Foreground" Value="{DynamicResource TabItemHeaderForegroundUnselectedPointerOver}" />
</Style>
<!-- Selected PointerOver state -->
<Style Selector="^:selected:pointerover /template/ Border#PART_LayoutRoot">
<Setter Property="Background" Value="{DynamicResource TabItemHeaderBackgroundSelectedPointerOver}" />
<Setter Property="TextElement.Foreground" Value="{DynamicResource TabItemHeaderForegroundSelectedPointerOver}" />
</Style>
<!-- Pressed state -->
<Style Selector="^:pressed /template/ Border#PART_LayoutRoot">
<Setter Property="Background" Value="{DynamicResource TabItemHeaderBackgroundUnselectedPressed}" />
<Setter Property="TextElement.Foreground" Value="{DynamicResource TabItemHeaderForegroundUnselectedPressed}" />
<Setter Property="Border.Background" Value="{DynamicResource TabItemLinePipeSelectedBackground}" />
</Style>
<!-- Selected Pressed state -->
@ -90,52 +83,48 @@
<!-- TabStripPlacement States Group -->
<Style Selector="^[TabStripPlacement=Top]">
<Style Selector="^ /template/Border#PART_SelectedPipe">
<Setter Property="Height" Value="2" />
<Setter Property="Margin" Value="0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Bottom" />
<Setter Property="Border.Height" Value="2" />
<Setter Property="Border.Margin" Value="0" />
<Setter Property="Border.HorizontalAlignment" Value="Stretch" />
<Setter Property="Border.VerticalAlignment" Value="Bottom" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^ /template/ Label#PART_ContentPresenter">
<Setter Property="Margin" Value="0,0,0,4" />
</Style>
</Style>
<Style Selector="^[TabStripPlacement=Bottom]">
<Style Selector="^ /template/Border#PART_SelectedPipe">
<Setter Property="Height" Value="2" />
<Setter Property="Margin" Value="0" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Border.Height" Value="2" />
<Setter Property="Border.Margin" Value="0" />
<Setter Property="Border.HorizontalAlignment" Value="Stretch" />
<Setter Property="Border.VerticalAlignment" Value="Top" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Style Selector="^ /template/ Label#PART_ContentPresenter">
<Setter Property="Margin" Value="0,4,0,0" />
</Style>
</Style>
<Style Selector="^[TabStripPlacement=Left] /template/ Border#PART_SelectedPipe">
<Setter Property="Border.Width" Value="2" />
<Setter Property="Border.Margin" Value="0,0,8,0" />
<Setter Property="Border.HorizontalAlignment" Value="Left" />
<Setter Property="Border.VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^[TabStripPlacement=Left] /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Margin" Value="8,0,0,0" />
</Style>
<Style Selector="^[TabStripPlacement=Top] /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Margin" Value="0,0,0,8" />
</Style>
<Style Selector="^[TabStripPlacement=Right] /template/ Border#PART_SelectedPipe">
<Setter Property="Width" Value="2" />
<Setter Property="Margin" Value="2,0,0,0" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^[TabStripPlacement=Right] /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Margin" Value="0,0,8,0" />
<Style Selector="^[TabStripPlacement=Left]">
<Style Selector="^/template/ Border#PART_SelectedPipe">
<Setter Property="Border.Width" Value="2" />
<Setter Property="Border.Margin" Value="0" />
<Setter Property="Border.HorizontalAlignment" Value="Left" />
<Setter Property="Border.VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^ /template/ Label#PART_ContentPresenter">
<Setter Property="Margin" Value="8,0,0,0" />
</Style>
</Style>
<Style Selector="^[TabStripPlacement=Right]">
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="TabItem.HorizontalContentAlignment" Value="Right" />
<Style Selector="^ /template/ Border#PART_SelectedPipe">
<Setter Property="Border.Width" Value="2" />
<Setter Property="Border.Margin" Value="0" />
<Setter Property="Border.HorizontalAlignment" Value="Right" />
<Setter Property="Border.VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="^ /template/ Label#PART_ContentPresenter">
<Setter Property="Margin" Value="0,0,8,0" />
</Style>
</Style>
</ControlTheme>

View File

@ -1,4 +1,6 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary
xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=System.Runtime">
<!-- Add Resources Here -->
<!-- Line -->
<SolidColorBrush x:Key="TabItemLinePipeBackground" Color="Transparent" />
@ -7,11 +9,11 @@
<SolidColorBrush x:Key="TabItemLinePipePressedBorderBrush" Opacity="0.13" Color="#2E3238" />
<SolidColorBrush x:Key="TabItemLineHeaderForeground" Opacity="0.62" Color="#1C1F23" />
<SolidColorBrush x:Key="TabItemLineHeaderPointeroverForeground" Color="#1C1F23" />
<SolidColorBrush x:Key="TabItemLineHeaderPointeroverForeground" Opacity="0.8" Color="#1C1F23" />
<SolidColorBrush x:Key="TabItemLineHeaderSelectedForeground" Color="#1C1F23" />
<SolidColorBrush x:Key="TabItemLineHeaderBackground" Color="Transparent" />
<SolidColorBrush x:Key="TabItemLineHeaderPointeroverBackground" Color="Transparent" />
<SolidColorBrush x:Key="TabItemLineHeaderSelectedForeground" Color="Transparent" />
<FontWeight x:Key="TabItemSelectedFontWeight">600</FontWeight>
</ResourceDictionary>