feat: extract common button style.

This commit is contained in:
rabbitism
2024-01-23 19:55:23 +08:00
parent 7c29320ad9
commit 61ebba897b
9 changed files with 137 additions and 49 deletions

View File

@@ -7,18 +7,29 @@
<Setter Property="Template">
<ControlTemplate TargetType="u:DialogControl">
<Border
Classes="Shadow"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Classes="Hover"
IsHitTestVisible="True"
Padding="2"
Theme="{DynamicResource CardBorder}">
<Grid RowDefinitions="Auto, *, Auto">
<StackPanel Grid.Row="0" HorizontalAlignment="Right">
<Button Name="{x:Static u:DialogControl.PART_CloseButton}" >Close</Button>
</StackPanel>
<DockPanel
Name="{x:Static u:DialogControl.PART_TitleArea}"
Grid.Row="0"
LastChildFill="False"
Background="Transparent">
<TextBlock DockPanel.Dock="Left" Text="Title" Margin="8 8 0 0" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
DockPanel.Dock="Right"
Margin="0,4,4,0"
Theme="{DynamicResource CloseButton}">
</Button>
</DockPanel>
<ContentPresenter
Grid.Row="0"
Grid.RowSpan="2"
Grid.RowSpan="3"
Content="{TemplateBinding Content}" />
</Grid>
</Border>
@@ -58,8 +69,16 @@
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<ChromeOverlayLayer />
<Grid RowDefinitions="Auto, *, Auto">
<Button Name="{x:Static u:DialogWindow.PART_CloseButton}" VerticalAlignment="Top" HorizontalAlignment="Right">Close</Button>
<ContentPresenter Grid.Row="0" Grid.RowSpan="2" Content="{TemplateBinding Content}" />
<Button
Name="{x:Static u:DialogWindow.PART_CloseButton}"
HorizontalAlignment="Right"
VerticalAlignment="Top">
Close
</Button>
<ContentPresenter
Grid.Row="0"
Grid.RowSpan="2"
Content="{TemplateBinding Content}" />
</Grid>
</Panel>
</ControlTemplate>

View File

@@ -0,0 +1,42 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Add Resources Here -->
<ControlTheme x:Key="CloseButton" TargetType="Button">
<Setter Property="CornerRadius" Value="6" />
<Setter Property="Margin" Value="0, 4" />
<Setter Property="Padding" Value="4" />
<Setter Property="Height" Value="28" />
<Setter Property="Width" Value="28" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Template">
<ControlTemplate TargetType="Button">
<Border
Name="PART_Border"
Padding="{TemplateBinding Padding}"
Background="Transparent"
CornerRadius="{TemplateBinding CornerRadius}">
<PathIcon
Width="12"
Height="12"
Data="{DynamicResource WindowCloseIconGlyph}"/>
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:pointerover /template/ Border">
<Setter Property="Background" Value="{DynamicResource CaptionButtonClosePointeroverBackground}" />
</Style>
<Style Selector="^:pointerover /template/ PathIcon">
<Setter Property="Foreground" Value="White" />
</Style>
<Style Selector="^:pressed /template/ Border">
<Setter Property="Background" Value="{DynamicResource CaptionButtonClosePressedBackground}" />
</Style>
<Style Selector="^:pressed /template/ PathIcon">
<Setter Property="Foreground" Value="White" />
</Style>
</ControlTheme>
</ResourceDictionary>

View File

@@ -45,23 +45,7 @@
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="1"
Margin="0,4,4,0"
Background="{DynamicResource CaptionButtonClosePointeroverBackground}"
BorderBrush="{DynamicResource CaptionButtonClosePressedBackground}"
Theme="{DynamicResource CaptionButton}">
<Button.Styles>
<Style Selector="Button:pointerover">
<Setter Property="Foreground" Value="White" />
</Style>
<Style Selector="Button:pressed">
<Setter Property="Foreground" Value="White" />
</Style>
</Button.Styles>
<PathIcon
Width="12"
Height="12"
Data="{DynamicResource WindowCloseIconGlyph}"
Foreground="{Binding $parent[Button].Foreground}" />
</Button>
Theme="{DynamicResource CloseButton}"/>
</Grid>
<Grid
Grid.Row="1"

View File

@@ -5,6 +5,7 @@
<ResourceInclude Source="Banner.axaml" />
<ResourceInclude Source="ButtonGroup.axaml" />
<ResourceInclude Source="Dialog.axaml" />
<ResourceInclude Source="DialogShared.axaml" />
<ResourceInclude Source="Divider.axaml" />
<ResourceInclude Source="DualBadge.axaml" />
<ResourceInclude Source="IconButton.axaml" />