feat: add dismiss Button.

This commit is contained in:
Zhang Dian 2024-11-24 22:46:36 +08:00
parent 7ac603b18e
commit ed6b8c7469
4 changed files with 44 additions and 37 deletions

View File

@ -112,23 +112,12 @@
<ListBox <ListBox
Grid.Row="1" Grid.Row="1"
ItemsSource="{Binding Songs}" /> ItemsSource="{Binding Songs}" />
<ToggleSwitch <ToggleButton
Grid.Row="2" Grid.Row="2"
Theme="{DynamicResource ButtonToggleSwitch}" Theme="{DynamicResource SplitViewToggleButton}"
HorizontalAlignment="Left"
IsChecked="{Binding #SplitView.IsPaneOpen}"> IsChecked="{Binding #SplitView.IsPaneOpen}">
<ToggleSwitch.OnContent> </ToggleButton>
<PathIcon
Width="16"
Height="16"
Data="{StaticResource NavigationMenuExpandIconGlyph}" />
</ToggleSwitch.OnContent>
<ToggleSwitch.OffContent>
<PathIcon
Width="16"
Height="16"
Data="{StaticResource NavigationMenuExpandIconGlyph}" />
</ToggleSwitch.OffContent>
</ToggleSwitch>
</Grid> </Grid>
</SplitView.Pane> </SplitView.Pane>

View File

@ -1,6 +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">
<ControlTheme x:Key="NavigationTab" TargetType="TabControl"> <ControlTheme x:Key="NavigationTab" TargetType="TabControl">
<Setter Property="TabControl.Template"> <Setter Property="Template">
<ControlTemplate TargetType="TabControl"> <ControlTemplate TargetType="TabControl">
<Border <Border
HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
@ -10,7 +10,10 @@
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"> CornerRadius="{TemplateBinding CornerRadius}">
<DockPanel> <DockPanel>
<ScrollViewer DockPanel.Dock="Left" VerticalScrollBarVisibility="Auto"> <ScrollViewer
DockPanel.Dock="Left"
Name="PART_ScrollViewer"
VerticalScrollBarVisibility="Auto">
<Panel DockPanel.Dock="{TemplateBinding TabStripPlacement}"> <Panel DockPanel.Dock="{TemplateBinding TabStripPlacement}">
<ItemsPresenter Name="PART_ItemsPresenter"> <ItemsPresenter Name="PART_ItemsPresenter">
<ItemsPresenter.ItemsPanel> <ItemsPresenter.ItemsPanel>
@ -19,7 +22,8 @@
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ItemsPresenter.ItemsPanel> </ItemsPresenter.ItemsPanel>
</ItemsPresenter> </ItemsPresenter>
<Border Name="PART_BorderSeparator" Background="{DynamicResource TabItemLinePipePressedBorderBrush}" /> <Border Name="PART_BorderSeparator"
Background="{DynamicResource TabItemLinePipePressedBorderBrush}" />
</Panel> </Panel>
</ScrollViewer> </ScrollViewer>
<ContentPresenter <ContentPresenter
@ -38,5 +42,8 @@
<Setter Property="VerticalAlignment" Value="Stretch" /> <Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="HorizontalAlignment" Value="Left" />
</Style> </Style>
<Style Selector="^.Dismiss /template/ ScrollViewer#PART_ScrollViewer">
<Setter Property="IsVisible" Value="False" />
</Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>

View File

@ -1,18 +1,26 @@
<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">
<ControlTheme x:Key="SplitViewToggleButton" TargetType="ToggleButton"> <ControlTheme x:Key="SplitViewToggleButton" TargetType="ToggleButton">
<Setter Property="ToggleButton.Template"> <Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Padding" Value="8" />
<Setter Property="Foreground" Value="{DynamicResource ButtonDefaultTertiaryForeground}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="CornerRadius" Value="3" />
<Setter Property="Content"
Value="M5 2H19C20.6569 2 22 3.34315 22 5V19C22 20.6569 20.6569 22 19 22H5C3.34315 22 2 20.6569 2 19V5C2 3.34315 3.34315 2 5 2ZM6 4C5.44772 4 5 4.44772 5 5V19C5 19.5523 5.44772 20 6 20H9C9.55229 20 10 19.5523 10 19V5C10 4.44772 9.55229 4 9 4H6Z" />
<Setter Property="Template">
<ControlTemplate TargetType="ToggleButton"> <ControlTemplate TargetType="ToggleButton">
<Border <Border
Name="Background" Name="Background"
Padding="8" Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
CornerRadius="3"> CornerRadius="{TemplateBinding CornerRadius}">
<PathIcon <PathIcon
Name="Icon" Name="Icon"
Width="16" Theme="{DynamicResource InnerPathIcon}"
Height="16" Data="{TemplateBinding Content}"
Data="M5 2H19C20.6569 2 22 3.34315 22 5V19C22 20.6569 20.6569 22 19 22H5C3.34315 22 2 20.6569 2 19V5C2 3.34315 3.34315 2 5 2ZM6 4C5.44772 4 5 4.44772 5 5V19C5 19.5523 5.44772 20 6 20H9C9.55229 20 10 19.5523 10 19V5C10 4.44772 9.55229 4 9 4H6Z" Foreground="{TemplateBinding Foreground}" />
Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

View File

@ -21,27 +21,29 @@
</UserControl.Resources> </UserControl.Resources>
<Grid RowDefinitions="Auto, *"> <Grid RowDefinitions="Auto, *">
<Border <Border
Grid.Row="0"
Margin="8" Margin="8"
Padding="12,4" Padding="12,4"
Theme="{DynamicResource CardBorder}"> Theme="{DynamicResource CardBorder}">
<Grid VerticalAlignment="Center" ColumnDefinitions="*, Auto"> <Panel>
<StackPanel Grid.Column="0" Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock <ToggleButton
Name="ExpandButton"
Theme="{DynamicResource SplitViewToggleButton}" />
<SelectableTextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
Classes="H6" Classes="H6"
Text="Semi Avalonia" Text="Semi Avalonia"
Theme="{DynamicResource TitleTextBlock}" /> Theme="{DynamicResource TitleSelectableTextBlock}" />
<TextBlock <SelectableTextBlock
Margin="8,0"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="/" /> Text="/" />
<TextBlock <SelectableTextBlock
Margin="8,0"
VerticalAlignment="Center" VerticalAlignment="Center"
Classes="Secondary" Classes="Secondary"
Text="{ReflectionBinding #tab.SelectedItem.Header}" /> Text="{ReflectionBinding #tab.SelectedItem.Header}" />
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button <Button
Click="OpenDocumentation" Click="OpenDocumentation"
Theme="{DynamicResource BorderlessButton}" Theme="{DynamicResource BorderlessButton}"
@ -102,7 +104,7 @@
</Button.Styles> </Button.Styles>
</Button> </Button>
</StackPanel> </StackPanel>
</Grid> </Panel>
</Border> </Border>
<TabControl <TabControl
Name="tab" Name="tab"
@ -111,6 +113,7 @@
Padding="20,0,0,0" Padding="20,0,0,0"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
TabStripPlacement="Left" TabStripPlacement="Left"
Classes.Dismiss="{Binding #ExpandButton.IsChecked}"
Theme="{DynamicResource NavigationTab}"> Theme="{DynamicResource NavigationTab}">
<TabItem Header="Overview"> <TabItem Header="Overview">
<pages:Overview /> <pages:Overview />