chore: add avalonia TabControl demo.

This commit is contained in:
NaBian committed 2025-02-09 21:32:04 +08:00
1 parent bbb2db1696
commit 045ced1c73
12 files changed
+685 -87

No files matched your search

@@ -1,6 +1,74 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="{x:Type TabControl}"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="clr-namespace:HandyControl.Controls"
xmlns:tools="clr-namespace:HandyControl.Tools"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<ControlTheme x:Key="TabItemStyle"
TargetType="TabItem">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource TitleBrush}" />
<Setter Property="Margin"
Value="0" />
<Setter Property="Padding"
Value="{StaticResource DefaultControlPadding}" />
<Setter Property="MinHeight"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Template">
<ControlTemplate>
<Panel>
<Border Name="mainBorder"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0"
Background="{TemplateBinding Background}"
Margin="0" />
<ContentPresenter Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
CornerRadius="{TemplateBinding CornerRadius}"
RecognizesAccessKey="True" />
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
<Style Selector="^:selected">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
<Style Selector="^[TabStripPlacement=Left] /template/ Border#mainBorder">
<Setter Property="BorderThickness"
Value="0,0,2,0" />
</Style>
<Style Selector="^[TabStripPlacement=Top] /template/ Border#mainBorder">
<Setter Property="BorderThickness"
Value="0,0,0,2" />
</Style>
<Style Selector="^[TabStripPlacement=Right] /template/ Border#mainBorder">
<Setter Property="BorderThickness"
Value="2,0,0,0" />
</Style>
<Style Selector="^[TabStripPlacement=Bottom] /template/ Border#mainBorder">
<Setter Property="BorderThickness"
Value="0,2,0,0" />
</Style>
</Style>
</ControlTheme>
<ControlTheme x:Key="TabControlBaseStyle"
TargetType="TabControl">
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
@@ -8,6 +76,8 @@
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="ItemContainerTheme"
Value="{StaticResource TabItemStyle}" />
<Setter Property="Template">
<ControlTemplate>
<DockPanel>
@@ -46,29 +116,290 @@
Value="Left" />
</Style>
<Style Selector="^[TabStripPlacement=Left] /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel">
<Setter Property="Orientation"
Value="Vertical" />
</Style>
<Style Selector="^[TabStripPlacement=Right] /template/ ItemsPresenter#PART_ItemsPresenter">
<Setter Property="DockPanel.Dock"
Value="Right" />
</Style>
<Style Selector="^[TabStripPlacement=Left] /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel">
<Setter Property="Orientation"
Value="Vertical" />
</Style>
<Style Selector="^[TabStripPlacement=Right] /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel">
<Setter Property="Orientation"
Value="Vertical" />
</Style>
</ControlTheme>
<Style Selector="^.inline">
<ControlTheme x:Key="{x:Type TabControl}"
BasedOn="{StaticResource TabControlBaseStyle}"
TargetType="TabControl" />
<ControlTheme x:Key="TabItemInLine"
BasedOn="{StaticResource TabItemStyle}"
TargetType="TabItem">
<Setter Property="MinWidth"
Value="0" />
</ControlTheme>
<ControlTheme x:Key="TabControlInLine"
BasedOn="{StaticResource TabControlBaseStyle}"
TargetType="TabControl">
<Setter Property="ItemContainerTheme"
Value="{StaticResource TabItemInLine}" />
<Style Selector="^[TabStripPlacement=Left], ^[TabStripPlacement=Right]">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
<UniformGrid Rows="0"
Columns="1" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<Style Selector="^[TabStripPlacement=Top], ^[TabStripPlacement=Bottom]">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Rows="1"
Columns="0" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTheme>
<ControlTheme x:Key="TabItemCapsuleBaseStyle"
TargetType="TabItem">
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="VerticalAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="hc:BorderElement.CornerRadius"
Value="0" />
<Setter Property="CornerRadius"
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
<Setter Property="MinHeight"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="Padding"
Value="10,0" />
<Setter Property="Margin"
Value="-1,0,0,0" />
<Setter Property="Template">
<ControlTemplate>
<Border x:Name="rootBorder"
CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
CornerRadius="{TemplateBinding CornerRadius}"
RecognizesAccessKey="True" />
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
<Style Selector="^:pointerover">
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
</Style>
<Style Selector="^:selected">
<Setter Property="Background"
Value="{Binding $self.(hc:TitleElement.Background)}" />
<Setter Property="Foreground"
Value="{Binding $self.(hc:TitleElement.Foreground)}" />
<Setter Property="BorderBrush"
Value="{Binding $self.(hc:TitleElement.BorderBrush)}" />
<Setter Property="ZIndex"
Value="{x:Static system:Int32.MaxValue}" />
</Style>
<Style Selector="^[TabStripPlacement=Left], ^[TabStripPlacement=Right]">
<Setter Property="Margin"
Value="0,-1,0,0" />
</Style>
<Style Selector="^[TabStripPlacement=Top], ^[TabStripPlacement=Bottom]">
<Setter Property="Margin"
Value="-1,0,0,0" />
</Style>
</ControlTheme>
<ControlTheme x:Key="TabItemCapsuleDefault"
BasedOn="{StaticResource TabItemCapsuleBaseStyle}"
TargetType="TabItem" />
<ControlTheme x:Key="TabItemCapsuleHorizontalFirst"
BasedOn="{StaticResource TabItemCapsuleBaseStyle}"
TargetType="TabItem">
<Setter Property="hc:BorderElement.CornerRadius"
Value="4,0,0,4" />
<Setter Property="Margin"
Value="0" />
</ControlTheme>
<ControlTheme x:Key="TabItemCapsuleHorizontalLast"
BasedOn="{StaticResource TabItemCapsuleBaseStyle}"
TargetType="TabItem">
<Setter Property="hc:BorderElement.CornerRadius"
Value="0,4,4,0" />
</ControlTheme>
<ControlTheme x:Key="TabItemCapsuleSingle"
BasedOn="{StaticResource TabItemCapsuleBaseStyle}"
TargetType="TabItem">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{StaticResource DefaultCornerRadius}" />
</ControlTheme>
<ControlTheme x:Key="TabItemCapsuleVerticalFirst"
BasedOn="{StaticResource TabItemCapsuleBaseStyle}"
TargetType="TabItem">
<Setter Property="hc:BorderElement.CornerRadius"
Value="4,4,0,0" />
<Setter Property="Margin"
Value="0" />
</ControlTheme>
<ControlTheme x:Key="TabItemCapsuleVerticalLast"
BasedOn="{StaticResource TabItemCapsuleBaseStyle}"
TargetType="TabItem">
<Setter Property="hc:BorderElement.CornerRadius"
Value="0,0,4,4" />
</ControlTheme>
<ControlTheme x:Key="TabControlCapsule"
TargetType="TabControl">
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="hc:TitleElement.BorderBrush"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="hc:TitleElement.Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="hc:TitleElement.Foreground"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="hc:ItemsControlAttach.ItemsContainerThemeSelector">
<Setter.Value>
<tools:TabItemCapsuleThemeSelector />
</Setter.Value>
</Setter>
<Setter Property="Template">
<ControlTemplate>
<DockPanel>
<ItemsPresenter Name="PART_ItemsPresenter"
ItemsPanel="{TemplateBinding ItemsPanel}" />
<Border Padding="{TemplateBinding Padding}"
Margin="0,6,0,0"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<ContentPresenter Name="PART_SelectedContentHost"
Margin="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding SelectedContent}"
ContentTemplate="{TemplateBinding SelectedContentTemplate}" />
</Border>
</DockPanel>
</ControlTemplate>
</Setter>
<Style Selector="^[TabStripPlacement=Top] /template/ ItemsPresenter#PART_ItemsPresenter">
<Setter Property="DockPanel.Dock"
Value="Top" />
<Setter Property="Margin"
Value="0,0,0,6" />
</Style>
<Style Selector="^[TabStripPlacement=Bottom] /template/ ItemsPresenter#PART_ItemsPresenter">
<Setter Property="DockPanel.Dock"
Value="Bottom" />
<Setter Property="Margin"
Value="0,6,0,0" />
</Style>
<Style Selector="^[TabStripPlacement=Left] /template/ ItemsPresenter#PART_ItemsPresenter">
<Setter Property="DockPanel.Dock"
Value="Left" />
<Setter Property="Margin"
Value="0,0,6,0" />
</Style>
<Style Selector="^[TabStripPlacement=Right] /template/ ItemsPresenter#PART_ItemsPresenter">
<Setter Property="DockPanel.Dock"
Value="Right" />
<Setter Property="Margin"
Value="6,0,0,0" />
</Style>
<Style Selector="^[TabStripPlacement=Left], ^[TabStripPlacement=Right]">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Rows="0"
Columns="1"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<Style Selector="^[TabStripPlacement=Top], ^[TabStripPlacement=Bottom]">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Rows="1"
Columns="0"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTheme>
<ControlTheme x:Key="TabControlCapsuleSolid"
BasedOn="{StaticResource TabControlCapsule}"
TargetType="TabControl">
<Setter Property="hc:TitleElement.BorderBrush"
Value="{DynamicResource TitleBrush}" />
<Setter Property="hc:TitleElement.Background"
Value="{DynamicResource TitleBrush}" />
<Setter Property="hc:TitleElement.Foreground"
Value="{DynamicResource TextIconBrush}" />
</ControlTheme>
</ResourceDictionary>
@@ -1,56 +0,0 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="{x:Type TabItem}"
TargetType="TabItem">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="Background"
Value="{DynamicResource RegionBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource TitleBrush}" />
<Setter Property="Margin"
Value="0" />
<Setter Property="Padding"
Value="{StaticResource DefaultControlPadding}" />
<Setter Property="MinHeight"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Template">
<ControlTemplate>
<Panel>
<Border Name="mainBorder"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0"
Background="{TemplateBinding Background}"
Margin="0" />
<ContentPresenter Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
CornerRadius="{TemplateBinding CornerRadius}"
RecognizesAccessKey="True" />
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
<Style Selector="^:selected">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryBrush}" />
<Style Selector="^ /template/ Border#mainBorder">
<Setter Property="BorderThickness"
Value="0,0,0,2" />
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>
@@ -26,7 +26,6 @@
<MergeResourceInclude Source="/Themes/Styles/CheckBox.axaml" />
<MergeResourceInclude Source="/Themes/Styles/Border.axaml" />
<MergeResourceInclude Source="/Themes/Styles/ItemsControl.axaml" />
<MergeResourceInclude Source="/Themes/Styles/TabItem.axaml" />
<MergeResourceInclude Source="/Themes/Styles/TabControl.axaml" />
<MergeResourceInclude Source="/Themes/Styles/ScrollViewer.axaml" />
<MergeResourceInclude Source="/Themes/Styles/ListBox.axaml" />