Browse Source

Ported ButtonSpinner to ControlTheme.

pull/8479/head
Steven Kirk 4 years ago
parent
commit
c15837b743
  1. 228
      src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml

228
src/Avalonia.Themes.Fluent/Controls/ButtonSpinner.xaml

@ -3,106 +3,144 @@
xmlns:sys="clr-namespace:System;assembly=netstandard" xmlns:sys="clr-namespace:System;assembly=netstandard"
xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls" xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
x:CompileBindings="True"> x:CompileBindings="True">
<Design.PreviewWith> <Design.PreviewWith>
<Border Padding="20" Background="Black"> <Border Padding="20">
<StackPanel Spacing="20"> <StackPanel Spacing="20">
<ButtonSpinner ButtonSpinnerLocation="Right" <ButtonSpinner Content="Right spinner" />
Content="Right disabled inline spinner" <ButtonSpinner ButtonSpinnerLocation="Left"
AllowSpin="False"> Content="Left spinner" />
<DataValidationErrors.Error> <ButtonSpinner BorderThickness="2"
<sys:Exception /> BorderBrush="Blue"
</DataValidationErrors.Error> Content="Right Border" />
</ButtonSpinner> <ButtonSpinner ButtonSpinnerLocation="Left"
<ButtonSpinner ButtonSpinnerLocation="Left" BorderThickness="2"
Content="Left spinner" /> BorderBrush="Blue"
<ButtonSpinner ShowButtonSpinner="False" Content="Left Border" />
Content="Hide spinner" /> <ButtonSpinner Content="Right disabled"
</StackPanel> AllowSpin="False"/>
</Border> <ButtonSpinner ButtonSpinnerLocation="Left"
</Design.PreviewWith> Content="Left disabled"
AllowSpin="False"/>
<ButtonSpinner ShowButtonSpinner="False"
Content="Hide spinner" />
<ButtonSpinner Content="Error"
AllowSpin="False">
<DataValidationErrors.Error>
<sys:Exception>
<x:Arguments>
<x:String>Error</x:String>
</x:Arguments>
</sys:Exception>
</DataValidationErrors.Error>
</ButtonSpinner>
</StackPanel>
</Border>
</Design.PreviewWith>
<converters:MarginMultiplierConverter x:Key="ButtonSpinner_OnlyLeftThinknessConverter" <converters:MarginMultiplierConverter x:Key="ButtonSpinnerLeftThickness" Indent="1" Left="True" />
Indent="1" <converters:MarginMultiplierConverter x:Key="ButtonSpinnerRightThickness" Indent="1" Right="True" />
Left="True" /> <StreamGeometry x:Key="ButtonSpinnerIncreaseButtonIcon">M0,9 L10,0 20,9 19,10 10,2 1,10 z</StreamGeometry>
<converters:MarginMultiplierConverter x:Key="ButtonSpinner_OnlyRightThinknessConverter" <StreamGeometry x:Key="ButtonSpinnerDecreaseButtonIcon">M0,1 L10,10 20,1 19,0 10,8 1,0 z</StreamGeometry>
Indent="1"
Right="True" />
<StreamGeometry x:Key="ButtonSpinnerIncreaseButtonIcon">M0,9 L10,0 20,9 19,10 10,2 1,10 z</StreamGeometry> <ControlTheme x:Key="FluentButtonSpinnerRepeatButton" TargetType="RepeatButton" BasedOn="{StaticResource {x:Type RepeatButton}}">
<StreamGeometry x:Key="ButtonSpinnerDecreaseButtonIcon">M0,1 L10,10 20,1 19,0 10,8 1,0 z</StreamGeometry> <Setter Property="CornerRadius" Value="0"/>
<Setter Property="MinWidth" Value="34" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</ControlTheme>
<ControlTheme x:Key="{x:Type ButtonSpinner}" TargetType="ButtonSpinner"> <ControlTheme x:Key="{x:Type ButtonSpinner}" TargetType="ButtonSpinner">
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" /> <Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
<Setter Property="Padding" Value="10, 0" /> <Setter Property="Padding" Value="10, 0" />
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" /> <Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" /> <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" /> <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" /> <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" /> <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Focusable" Value="True" /> <Setter Property="Focusable" Value="True"/>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<DataValidationErrors> <DataValidationErrors>
<Border Background="{TemplateBinding Background}" <Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}" CornerRadius="{TemplateBinding CornerRadius}"
MinHeight="{TemplateBinding MinHeight}"> MinHeight="{TemplateBinding MinHeight}">
<Grid ColumnDefinitions="Auto,*,Auto"> <DockPanel>
<ContentPresenter Name="PART_ContentPresenter" <StackPanel Name="PART_SpinnerPanel"
Grid.Column="1" DockPanel.Dock="Right"
ContentTemplate="{TemplateBinding ContentTemplate}" Orientation="Horizontal"
Content="{TemplateBinding Content}" IsVisible="{TemplateBinding ShowButtonSpinner}">
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" <RepeatButton Name="PART_IncreaseButton"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}" /> BorderThickness="0"
<StackPanel Name="PART_SpinnerPanel" CornerRadius="0"
Orientation="Horizontal" VerticalAlignment="Stretch"
IsVisible="{TemplateBinding ShowButtonSpinner}"> VerticalContentAlignment="Center"
<RepeatButton Name="PART_IncreaseButton" Foreground="{TemplateBinding Foreground}"
Classes="ButtonSpinnerRepeatButton" FontSize="{TemplateBinding FontSize}"
VerticalContentAlignment="Center" MinWidth="34">
Foreground="{TemplateBinding Foreground}" <Path Fill="{TemplateBinding Foreground}"
BorderBrush="{TemplateBinding BorderBrush}" Width="16"
Background="{TemplateBinding Background}" Height="8"
FontSize="{TemplateBinding FontSize}"> Stretch="Uniform"
<Path Fill="{TemplateBinding Foreground}" Width="16" Height="8" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Data="{StaticResource ButtonSpinnerIncreaseButtonIcon}" /> HorizontalAlignment="Center"
</RepeatButton> VerticalAlignment="Center"
<RepeatButton Name="PART_DecreaseButton" Classes="ButtonSpinnerRepeatButton" Foreground="{TemplateBinding Foreground}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" VerticalContentAlignment="Center" FontSize="{TemplateBinding FontSize}"> Data="{StaticResource ButtonSpinnerIncreaseButtonIcon}" />
<Path Fill="{TemplateBinding Foreground}" Width="16" Height="8" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" Data="{StaticResource ButtonSpinnerDecreaseButtonIcon}" /> </RepeatButton>
</RepeatButton>
</StackPanel>
</Grid>
</Border>
</DataValidationErrors>
</ControlTemplate>
</Setter>
<Style Selector="^:error"> <Border BorderBrush="{TemplateBinding BorderBrush}"
<Setter Property="BorderBrush" Value="{DynamicResource SystemErrorTextColor}" /> BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerRightThickness}}"
</Style> VerticalAlignment="Stretch"/>
<Style Selector="^:left"> <RepeatButton Name="PART_DecreaseButton"
<Style Selector="^ /template/ StackPanel#PART_SpinnerPanel"> Background="{TemplateBinding Background}"
<Setter Property="Grid.Column" Value="0" /> BorderThickness="0"
</Style> CornerRadius="0"
<Style Selector="^ /template/ RepeatButton.ButtonSpinnerRepeatButton"> VerticalAlignment="Stretch"
<Setter Property="BorderThickness" Value="{Binding $parent[ButtonSpinner].BorderThickness, Converter={StaticResource ButtonSpinner_OnlyRightThinknessConverter}}" /> VerticalContentAlignment="Center"
</Style> Foreground="{TemplateBinding Foreground}"
</Style> FontSize="{TemplateBinding FontSize}"
MinWidth="34">
<Path Fill="{TemplateBinding Foreground}"
Width="16"
Height="8"
Stretch="Uniform"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="{StaticResource ButtonSpinnerDecreaseButtonIcon}" />
</RepeatButton>
</StackPanel>
<Style Selector="^:right"> <ContentPresenter Name="PART_ContentPresenter"
<Style Selector="^ /template/ StackPanel#PART_SpinnerPanel"> Grid.Column="1"
<Setter Property="Grid.Column" Value="2" /> BorderBrush="{TemplateBinding BorderBrush}"
</Style> BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerRightThickness}}"
<Style Selector="^ /template/ RepeatButton.ButtonSpinnerRepeatButton"> ContentTemplate="{TemplateBinding ContentTemplate}"
<Setter Property="BorderThickness" Value="{Binding $parent[ButtonSpinner].BorderThickness, Converter={StaticResource ButtonSpinner_OnlyLeftThinknessConverter}}" /> Content="{TemplateBinding Content}"
</Style> HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Padding="{TemplateBinding Padding}" />
</DockPanel>
</Border>
</DataValidationErrors>
</ControlTemplate>
</Setter>
<Style Selector="^:left">
<Style Selector="^ /template/ StackPanel#PART_SpinnerPanel">
<Setter Property="DockPanel.Dock" Value="Left"/>
</Style>
<Style Selector="^ /template/ ContentPresenter">
<Setter Property="BorderThickness" Value="{TemplateBinding BorderThickness, Converter={StaticResource ButtonSpinnerLeftThickness}}" />
</Style> </Style>
</ControlTheme> </Style>
<Style Selector="^:error">
<Setter Property="BorderBrush" Value="{DynamicResource SystemErrorTextColor}" />
</Style>
</ControlTheme>
</ResourceDictionary> </ResourceDictionary>

Loading…
Cancel
Save