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

@@ -189,6 +189,7 @@
<Style 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}" />
@@ -210,7 +211,7 @@
<RowDefinition x:Name="RowDefinition1" Height="*" />
</Grid.RowDefinitions>
<UniformGrid Rows="1" KeyboardNavigation.TabNavigation="Once" KeyboardNavigation.DirectionalNavigation="Cycle" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="headerPanel" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="0" Grid.Row="0"/>
<Border x:Name="contentPanel" Margin="0,6,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{DynamicResource BorderBrush}" Background="{TemplateBinding Background}" Grid.Column="0" Grid.Row="1">
<Border x:Name="contentPanel" Margin="0,6,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.Column="0" Grid.Row="1">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</Grid>
@@ -8,27 +8,28 @@ public class TabItemCapsuleStyleSelector : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
if (container is TabItem tabItem && VisualHelper.GetParent<TabControl>(tabItem) is { } tabControl)
if (container is not TabItem tabItem || VisualHelper.GetParent<TabControl>(tabItem) is not { } tabControl)
{
var count = tabControl.Items.Count;
if (count == 1)
{
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.TabItemCapsuleSingle);
}
var index = tabControl.ItemContainerGenerator.IndexFromContainer(tabItem);
return index == 0
? ResourceHelper.GetResourceInternal<Style>(
tabControl.TabStripPlacement == Dock.Top || tabControl.TabStripPlacement == Dock.Bottom
? ResourceToken.TabItemCapsuleHorizontalFirst
: ResourceToken.TabItemCapsuleVerticalFirst)
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
? tabControl.TabStripPlacement == Dock.Top || tabControl.TabStripPlacement == Dock.Bottom
? ResourceToken.TabItemCapsuleHorizontalLast
: ResourceToken.TabItemCapsuleVerticalLast
: ResourceToken.TabItemCapsuleDefault);
return null;
}
return null;
var count = tabControl.Items.Count;
if (count == 1)
{
return ResourceHelper.GetResourceInternal<Style>(ResourceToken.TabItemCapsuleSingle);
}
var index = tabControl.ItemContainerGenerator.IndexFromContainer(tabItem);
return index == 0
? ResourceHelper.GetResourceInternal<Style>(
tabControl.TabStripPlacement is Dock.Top or Dock.Bottom
? ResourceToken.TabItemCapsuleHorizontalFirst
: ResourceToken.TabItemCapsuleVerticalFirst)
: ResourceHelper.GetResourceInternal<Style>(index == count - 1
? tabControl.TabStripPlacement is Dock.Top or Dock.Bottom
? ResourceToken.TabItemCapsuleHorizontalLast
: ResourceToken.TabItemCapsuleVerticalLast
: ResourceToken.TabItemCapsuleDefault);
}
}