committed by
GitHub
39 changed files with 1603 additions and 246 deletions
@ -0,0 +1,37 @@ |
|||||
|
using Avalonia.Interactivity; |
||||
|
using Avalonia.Input; |
||||
|
|
||||
|
namespace Avalonia.Controls.Mixins |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Adds pressed functionality to control classes.
|
||||
|
///
|
||||
|
/// Adds the ':pressed' class when the item is pressed.
|
||||
|
/// </summary>
|
||||
|
public static class PressedMixin |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="PressedMixin"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TControl">The control type.</typeparam>
|
||||
|
public static void Attach<TControl>() where TControl : Control |
||||
|
{ |
||||
|
InputElement.PointerPressedEvent.AddClassHandler<TControl>((x, e) => HandlePointerPressed(x, e), RoutingStrategies.Tunnel); |
||||
|
InputElement.PointerReleasedEvent.AddClassHandler<TControl>((x, e) => HandlePointerReleased(x), RoutingStrategies.Tunnel); |
||||
|
InputElement.PointerCaptureLostEvent.AddClassHandler<TControl>((x, e) => HandlePointerReleased(x), RoutingStrategies.Tunnel); |
||||
|
} |
||||
|
|
||||
|
private static void HandlePointerPressed<TControl>(TControl sender, PointerPressedEventArgs e) where TControl : Control |
||||
|
{ |
||||
|
if (e.GetCurrentPoint(sender).Properties.IsLeftButtonPressed) |
||||
|
{ |
||||
|
((IPseudoClasses)sender.Classes).Set(":pressed", true); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static void HandlePointerReleased<TControl>(TControl sender) where TControl : Control |
||||
|
{ |
||||
|
((IPseudoClasses)sender.Classes).Set(":pressed", false); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,64 +1,192 @@ |
|||||
<Styles xmlns="https://github.com/avaloniaui"> |
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
|
<Design.PreviewWith> |
||||
|
<Border Padding="20"> |
||||
|
<StackPanel Spacing="10"> |
||||
|
<ComboBox PlaceholderText="Select an item"> |
||||
|
<ComboBoxItem>Item 1</ComboBoxItem> |
||||
|
<ComboBoxItem>Item 2</ComboBoxItem> |
||||
|
</ComboBox> |
||||
|
|
||||
|
<ComboBox IsEnabled="False"> |
||||
|
<ComboBoxItem>Item 1</ComboBoxItem> |
||||
|
<ComboBoxItem>Item 2</ComboBoxItem> |
||||
|
</ComboBox> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
</Design.PreviewWith> |
||||
|
<Styles.Resources> |
||||
|
<Thickness x:Key="ComboBoxTopHeaderMargin">0,0,0,4</Thickness> |
||||
|
<x:Int32 x:Key="ComboBoxPopupMaxNumberOfItems">15</x:Int32> |
||||
|
<x:Int32 x:Key="ComboBoxPopupMaxNumberOfItemsThatCanBeShownOnOneSide">7</x:Int32> |
||||
|
|
||||
|
<Thickness x:Key="ComboBoxPadding">12,5,0,7</Thickness> |
||||
|
<Thickness x:Key="ComboBoxEditableTextPadding">11,5,32,6</Thickness> |
||||
|
<x:Double x:Key="ComboBoxMinHeight">32</x:Double> |
||||
|
</Styles.Resources> |
||||
<Style Selector="ComboBox"> |
<Style Selector="ComboBox"> |
||||
<Setter Property="Background" Value="Transparent"/> |
<Setter Property="Padding" Value="{DynamicResource ComboBoxPadding}" /> |
||||
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> |
<Setter Property="MaxDropDownHeight" Value="504" /> |
||||
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/> |
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForeground}" /> |
||||
<Setter Property="Padding" Value="4"/> |
<Setter Property="Background" Value="{DynamicResource ComboBoxBackground}" /> |
||||
<Setter Property="MinHeight" Value="20"/> |
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxBorderBrush}" /> |
||||
|
<Setter Property="BorderThickness" Value="{DynamicResource ComboBoxBorderThemeThickness}" /> |
||||
|
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /> |
||||
|
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> |
||||
|
<Setter Property="HorizontalAlignment" Value="Left" /> |
||||
|
<Setter Property="VerticalAlignment" Value="Top" /> |
||||
|
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" /> |
||||
|
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> |
||||
|
<Setter Property="PlaceholderForeground" Value="{DynamicResource ComboBoxPlaceHolderForeground}" /> |
||||
<Setter Property="Template"> |
<Setter Property="Template"> |
||||
<ControlTemplate> |
<ControlTemplate> |
||||
<Border Name="border" |
<Grid RowDefinitions="Auto, *, Auto" ColumnDefinitions="*,32"> |
||||
Background="{TemplateBinding Background}" |
<ContentPresenter x:Name="HeaderContentPresenter" |
||||
BorderBrush="{TemplateBinding BorderBrush}" |
Grid.Row="0" |
||||
BorderThickness="{TemplateBinding BorderThickness}"> |
Grid.Column="0" |
||||
<Grid ColumnDefinitions="*,Auto"> |
Grid.ColumnSpan="2" |
||||
<ContentControl Content="{TemplateBinding SelectionBoxItem}" |
TextBlock.FontWeight="{DynamicResource ComboBoxHeaderThemeFontWeight}" |
||||
ContentTemplate="{TemplateBinding ItemTemplate}" |
Margin="{DynamicResource ComboBoxTopHeaderMargin}" |
||||
Margin="{TemplateBinding Padding}" |
VerticalAlignment="Top" /> |
||||
HorizontalAlignment="Left" |
<Border x:Name="Background" |
||||
VerticalAlignment="Center"/> |
Grid.Row="1" |
||||
<ToggleButton Name="toggle" |
Grid.Column="0" |
||||
BorderThickness="0" |
Grid.ColumnSpan="2" |
||||
|
Background="{TemplateBinding Background}" |
||||
|
BorderBrush="{TemplateBinding BorderBrush}" |
||||
|
BorderThickness="{TemplateBinding BorderThickness}" |
||||
|
CornerRadius="{DynamicResource ControlCornerRadius}" |
||||
|
MinWidth="{DynamicResource ComboBoxThemeMinWidth}" /> |
||||
|
|
||||
|
<Border x:Name="HighlightBackground" |
||||
|
Grid.Row="1" |
||||
|
Grid.Column="0" |
||||
|
Grid.ColumnSpan="2" |
||||
|
Background="{DynamicResource ComboBoxBackgroundUnfocused}" |
||||
|
BorderBrush="{DynamicResource ComboBoxBackgroundBorderBrushUnfocused}" |
||||
|
BorderThickness="{TemplateBinding BorderThickness}" |
||||
|
CornerRadius="{DynamicResource ControlCornerRadius}" |
||||
|
Opacity="0" /> |
||||
|
<TextBlock x:Name="PlaceholderTextBlock" |
||||
|
Grid.Row="1" |
||||
|
Grid.Column="0" |
||||
|
HorizontalAlignment="Left" |
||||
|
VerticalAlignment="Center" |
||||
|
Margin="{TemplateBinding Padding}" |
||||
|
Foreground="{TemplateBinding PlaceholderForeground}" |
||||
|
Text="{TemplateBinding PlaceholderText}" IsVisible="{TemplateBinding SelectionBoxItem, Converter={x:Static ObjectConverters.IsNull}}"/> |
||||
|
<ContentControl x:Name="ContentPresenter" |
||||
|
Content="{TemplateBinding SelectionBoxItem}" |
||||
|
ContentTemplate="{TemplateBinding ItemTemplate}" |
||||
|
Grid.Row="1" |
||||
|
Grid.Column="0" |
||||
|
Margin="{TemplateBinding Padding}" |
||||
|
HorizontalAlignment="Left" |
||||
|
VerticalAlignment="Center"> |
||||
|
</ContentControl> |
||||
|
|
||||
|
<Border x:Name="DropDownOverlay" |
||||
|
Grid.Row="1" |
||||
|
Grid.Column="1" |
||||
Background="Transparent" |
Background="Transparent" |
||||
ClickMode="Press" |
Margin="0,1,1,1" |
||||
Focusable="False" |
Width="30" IsVisible="False" |
||||
IsChecked="{TemplateBinding IsDropDownOpen, Mode=TwoWay}" |
HorizontalAlignment="Right" /> |
||||
Grid.Column="1"> |
|
||||
<Path Fill="{DynamicResource ThemeForegroundBrush}" |
<Viewbox UseLayoutRounding="False" |
||||
Width="8" |
MinHeight="{DynamicResource ComboBoxMinHeight}" |
||||
Height="4" |
Grid.Row="1" |
||||
Stretch="Uniform" |
Grid.Column="1" |
||||
HorizontalAlignment="Center" |
IsHitTestVisible="False" |
||||
VerticalAlignment="Center" |
Margin="0,0,10,0" Height="12" Width="12" |
||||
Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z"/> |
HorizontalAlignment="Right" |
||||
</ToggleButton> |
VerticalAlignment="Center"> |
||||
<Popup Name="PART_Popup" |
<Panel> |
||||
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}" |
<Panel Height="12" Width="12" /> |
||||
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}" |
<Path x:Name="DropDownGlyph" Stretch="Uniform" VerticalAlignment="Center" Data="M1939 486L2029 576L1024 1581L19 576L109 486L1024 1401L1939 486Z" /> |
||||
MaxHeight="{TemplateBinding MaxDropDownHeight}" |
</Panel> |
||||
PlacementTarget="{TemplateBinding}" |
</Viewbox> |
||||
StaysOpen="False"> |
<Popup Name="PART_Popup" |
||||
<Border BorderBrush="{DynamicResource ThemeBorderMidBrush}" |
WindowManagerAddShadowHint="False" |
||||
BorderThickness="1"> |
IsOpen="{TemplateBinding IsDropDownOpen, Mode=TwoWay}" |
||||
<ScrollViewer> |
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}" |
||||
<ItemsPresenter Name="PART_ItemsPresenter" |
MaxHeight="{TemplateBinding MaxDropDownHeight}" |
||||
Items="{TemplateBinding Items}" |
PlacementTarget="{TemplateBinding}" |
||||
ItemsPanel="{TemplateBinding ItemsPanel}" |
StaysOpen="False"> |
||||
ItemTemplate="{TemplateBinding ItemTemplate}" |
<Border x:Name="PopupBorder" |
||||
VirtualizationMode="{TemplateBinding VirtualizationMode}" |
Background="{DynamicResource ComboBoxDropDownBackground}" |
||||
|
BorderBrush="{DynamicResource ComboBoxDropDownBorderBrush}" |
||||
|
BorderThickness="{DynamicResource ComboBoxDropdownBorderThickness}" |
||||
|
Margin="0,-1,0,-1" |
||||
|
Padding="{DynamicResource ComboBoxDropdownBorderPadding}" |
||||
|
HorizontalAlignment="Stretch" |
||||
|
CornerRadius="{DynamicResource OverlayCornerRadius}"> |
||||
|
<ScrollViewer> |
||||
|
<ItemsPresenter Name="PART_ItemsPresenter" |
||||
|
Items="{TemplateBinding Items}" |
||||
|
Margin="{DynamicResource ComboBoxDropdownContentMargin}" |
||||
|
ItemsPanel="{TemplateBinding ItemsPanel}" |
||||
|
ItemTemplate="{TemplateBinding ItemTemplate}" |
||||
|
VirtualizationMode="{TemplateBinding VirtualizationMode}" |
||||
/> |
/> |
||||
</ScrollViewer> |
</ScrollViewer> |
||||
</Border> |
</Border> |
||||
</Popup> |
</Popup> |
||||
</Grid> |
</Grid> |
||||
</Border> |
|
||||
</ControlTemplate> |
</ControlTemplate> |
||||
</Setter> |
</Setter> |
||||
</Style> |
</Style> |
||||
<Style Selector="ComboBox:pointerover /template/ Border#border"> |
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/> |
<!-- NormalState --> |
||||
|
<Style Selector="ComboBox /template/ TextBlock#PlaceholderTextBlock"> |
||||
|
<Setter Property="Foreground" Value="{DynamicResource ComboBoxPlaceHolderForeground}"/> |
||||
</Style> |
</Style> |
||||
<Style Selector="ComboBox:disabled /template/ Border#border"> |
|
||||
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}" /> |
<Style Selector="ComboBox /template/ Path#DropDownGlyph"> |
||||
|
<Setter Property="Fill" Value="{DynamicResource ComboBoxDropDownGlyphForeground}"/> |
||||
</Style> |
</Style> |
||||
|
|
||||
|
<!-- PointerOver State --> |
||||
|
<Style Selector="ComboBox:pointerover /template/ Border#Background"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ComboBoxBackgroundPointerOver}"/> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxBorderBrushPointerOver}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<!-- Pressed State --> |
||||
|
<Style Selector="ComboBox:pressed /template/ Border#Background"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ComboBoxBackgroundPressed}"/> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxBorderBrushPressed}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<!-- Disabled State --> |
||||
|
<Style Selector="ComboBox:disabled /template/ Border#Background"> |
||||
|
<Setter Property="Background" Value="{DynamicResource ComboBoxBackgroundDisabled}"/> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxBorderBrushDisabled}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="ComboBox:disabled /template/ ContentPresenter#HeaderContentPresenter"> |
||||
|
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ComboBoxForegroundDisabled}"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="ComboBox:disabled /template/ ContentControl#ContentPresenter"> |
||||
|
<Setter Property="TextBlock.Foreground" Value="{DynamicResource ComboBoxForegroundDisabled}"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="ComboBox:disabled /template/ TextBlock#PlaceholderTextBlock"> |
||||
|
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForegroundDisabled}"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="ComboBox:disabled /template/ TextBlock#PlaceholderTextBlock"> |
||||
|
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForegroundDisabled}"/> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="ComboBox:disabled /template/ Path#DropDownGlyph"> |
||||
|
<Setter Property="Fill" Value="{DynamicResource ComboBoxDropDownGlyphForegroundDisabled}"/> |
||||
|
</Style> |
||||
|
|
||||
|
<!-- Focused State --> |
||||
|
|
||||
|
<!-- Focus Pressed State --> |
||||
|
|
||||
|
<!-- Unfocused State --> |
||||
|
|
||||
</Styles> |
</Styles> |
||||
|
|||||
@ -1,31 +1,43 @@ |
|||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<Style Selector="ListBox"> |
<Design.PreviewWith> |
||||
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/> |
<Border Padding="20"> |
||||
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> |
<ListBox> |
||||
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/> |
<ListBoxItem>Test</ListBoxItem> |
||||
<Setter Property="Padding" Value="4"/> |
<ListBoxItem>Test</ListBoxItem> |
||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> |
<ListBoxItem>Test</ListBoxItem> |
||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> |
<ListBoxItem>Test</ListBoxItem> |
||||
<Setter Property="Template"> |
</ListBox> |
||||
<ControlTemplate> |
</Border> |
||||
<Border Name="border" BorderBrush="{TemplateBinding BorderBrush}" |
</Design.PreviewWith> |
||||
BorderThickness="{TemplateBinding BorderThickness}"> |
<Style Selector="ListBox"> |
||||
<ScrollViewer Name="PART_ScrollViewer" |
<Setter Property="TextBlock.Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
Background="{TemplateBinding Background}" |
<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}" /> |
||||
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" |
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlForegroundBaseHighBrush}" /> |
||||
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"> |
<Setter Property="BorderThickness" Value="{DynamicResource ListBoxBorderThemeThickness}" /> |
||||
<ItemsPresenter Name="PART_ItemsPresenter" |
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" /> |
||||
Items="{TemplateBinding Items}" |
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> |
||||
ItemsPanel="{TemplateBinding ItemsPanel}" |
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" /> |
||||
ItemTemplate="{TemplateBinding ItemTemplate}" |
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> |
||||
Margin="{TemplateBinding Padding}" |
<Setter Property="Template"> |
||||
VirtualizationMode="{TemplateBinding VirtualizationMode}"/> |
<ControlTemplate> |
||||
</ScrollViewer> |
<Border Name="border" BorderBrush="{TemplateBinding BorderBrush}" |
||||
</Border> |
BorderThickness="{TemplateBinding BorderThickness}"> |
||||
</ControlTemplate> |
<ScrollViewer Name="PART_ScrollViewer" |
||||
</Setter> |
Background="{TemplateBinding Background}" |
||||
</Style> |
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}" |
||||
<Style Selector="ListBox:disabled /template/ Border#border"> |
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"> |
||||
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}" /> |
<ItemsPresenter Name="PART_ItemsPresenter" |
||||
</Style> |
Items="{TemplateBinding Items}" |
||||
|
ItemsPanel="{TemplateBinding ItemsPanel}" |
||||
|
ItemTemplate="{TemplateBinding ItemTemplate}" |
||||
|
Margin="{TemplateBinding Padding}" |
||||
|
VirtualizationMode="{TemplateBinding VirtualizationMode}"/> |
||||
|
</ScrollViewer> |
||||
|
</Border> |
||||
|
</ControlTemplate> |
||||
|
</Setter> |
||||
|
</Style> |
||||
|
<Style Selector="ListBox:disabled /template/ Border#border"> |
||||
|
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}" /> |
||||
|
</Style> |
||||
</Styles> |
</Styles> |
||||
|
|||||
@ -1,17 +1,21 @@ |
|||||
<Style xmlns="https://github.com/avaloniaui" Selector="PopupRoot"> |
<Styles xmlns="https://github.com/avaloniaui" |
||||
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}"/> |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<Setter Property="Template"> |
<Style Selector="PopupRoot"> |
||||
<ControlTemplate> |
<Setter Property="TransparencyLevelHint" Value="Transparent" /> |
||||
<Panel> |
<Setter Property="Background" Value="{x:Null}" /> |
||||
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> |
<Setter Property="Template"> |
||||
<VisualLayerManager IsPopup="True"> |
<ControlTemplate> |
||||
<ContentPresenter Name="PART_ContentPresenter" |
<Panel> |
||||
Background="{TemplateBinding Background}" |
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> |
||||
ContentTemplate="{TemplateBinding ContentTemplate}" |
<VisualLayerManager IsPopup="True"> |
||||
Content="{TemplateBinding Content}" |
<ContentPresenter Name="PART_ContentPresenter" |
||||
Padding="{TemplateBinding Padding}"/> |
Background="{TemplateBinding Background}" |
||||
</VisualLayerManager> |
ContentTemplate="{TemplateBinding ContentTemplate}" |
||||
</Panel> |
Content="{TemplateBinding Content}" |
||||
</ControlTemplate> |
Padding="{TemplateBinding Padding}"/> |
||||
</Setter> |
</VisualLayerManager> |
||||
</Style> |
</Panel> |
||||
|
</ControlTemplate> |
||||
|
</Setter> |
||||
|
</Style> |
||||
|
</Styles> |
||||
|
|||||
@ -1,60 +1,173 @@ |
|||||
<Styles xmlns="https://github.com/avaloniaui"> |
<Styles xmlns="https://github.com/avaloniaui"> |
||||
|
<Design.PreviewWith> |
||||
|
<Border Padding="20"> |
||||
|
<StackPanel Spacing="10"> |
||||
|
<RadioButton Content="Option 1" /> |
||||
|
<RadioButton Content="Option 2" /> |
||||
|
<RadioButton IsEnabled="False" Content="Option 3" /> |
||||
|
<RadioButton Content="Option 2" /> |
||||
|
</StackPanel> |
||||
|
</Border> |
||||
|
</Design.PreviewWith> |
||||
<Style Selector="RadioButton"> |
<Style Selector="RadioButton"> |
||||
<Setter Property="Background" Value="Transparent"/> |
<Setter Property="Background" Value="{DynamicResource RadioButtonBackground}" /> |
||||
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> |
<Setter Property="Foreground" Value="{DynamicResource RadioButtonForeground}" /> |
||||
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/> |
<Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrush}" /> |
||||
|
<Setter Property="Padding" Value="8,6,0,0" /> |
||||
|
<Setter Property="HorizontalAlignment" Value="Left" /> |
||||
|
<Setter Property="VerticalAlignment" Value="Center" /> |
||||
|
<Setter Property="HorizontalContentAlignment" Value="Left" /> |
||||
|
<Setter Property="VerticalContentAlignment" Value="Top" /> |
||||
|
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" /> |
||||
|
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> |
||||
|
<Setter Property="MinWidth" Value="120" /> |
||||
<Setter Property="Template"> |
<Setter Property="Template"> |
||||
<ControlTemplate> |
<ControlTemplate TargetType="RadioButton"> |
||||
<Grid ColumnDefinitions="Auto,*" Background="{TemplateBinding Background}"> |
<Border Name="RootBorder" |
||||
<Ellipse Name="border" |
Background="{TemplateBinding Background}" |
||||
Stroke="{TemplateBinding BorderBrush}" |
BorderBrush="{TemplateBinding BorderBrush}" |
||||
StrokeThickness="1" |
BorderThickness="{TemplateBinding BorderThickness}" |
||||
Width="18" |
CornerRadius="{DynamicResource ControlCornerRadius}"> |
||||
Height="18" |
<Grid ColumnDefinitions="20,*"> |
||||
VerticalAlignment="Center"/> |
<Grid VerticalAlignment="Top" |
||||
<Ellipse Name="checkMark" |
Height="32"> |
||||
Width="10" |
|
||||
Height="10" |
<Ellipse Name="OuterEllipse" |
||||
Stretch="Uniform" |
Width="20" Height="20" |
||||
UseLayoutRounding="False" |
UseLayoutRounding="False" |
||||
HorizontalAlignment="Center" |
StrokeThickness="{DynamicResource RadioButtonBorderThemeThickness}" /> |
||||
VerticalAlignment="Center"/> |
|
||||
<Ellipse Name="indeterminateMark" |
<Ellipse Name="CheckOuterEllipse" |
||||
Fill="{DynamicResource ThemeAccentBrush}" |
Width="20" Height="20" |
||||
Width="10" |
UseLayoutRounding="False" |
||||
Height="10" |
StrokeThickness="{DynamicResource RadioButtonBorderThemeThickness}" /> |
||||
Stretch="Uniform" |
|
||||
UseLayoutRounding="False" |
<Ellipse Name="CheckGlyph" |
||||
HorizontalAlignment="Center" |
Width="8" Height="8" |
||||
VerticalAlignment="Center"/> |
UseLayoutRounding="False" /> |
||||
<ContentPresenter Name="PART_ContentPresenter" |
</Grid> |
||||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|
||||
Content="{TemplateBinding Content}" |
<ContentPresenter Name="PART_ContentPresenter" |
||||
Margin="4,0,0,0" |
Content="{TemplateBinding Content}" |
||||
VerticalAlignment="Center" |
ContentTemplate="{TemplateBinding ContentTemplate}" |
||||
Grid.Column="1"/> |
TextBlock.Foreground="{TemplateBinding Foreground}" |
||||
</Grid> |
Margin="{TemplateBinding Padding}" |
||||
|
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" |
||||
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" |
||||
|
Grid.Column="1" /> |
||||
|
</Grid> |
||||
|
</Border> |
||||
</ControlTemplate> |
</ControlTemplate> |
||||
</Setter> |
</Setter> |
||||
</Style> |
</Style> |
||||
|
|
||||
<Style Selector="RadioButton:pointerover /template/ Ellipse#border"> |
<!-- Normal State --> |
||||
<Setter Property="Stroke" Value="{DynamicResource ThemeBorderHighBrush}"/> |
<Style Selector="RadioButton /template/ Ellipse#OuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStroke}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFill}" /> |
||||
</Style> |
</Style> |
||||
<Style Selector="RadioButton /template/ Ellipse#checkMark"> |
|
||||
<Setter Property="Fill" Value="{DynamicResource HighlightBrush}"/> |
<Style Selector="RadioButton /template/ Ellipse#CheckOuterEllipse"> |
||||
<Setter Property="IsVisible" Value="False"/> |
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStroke}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFill}" /> |
||||
|
<Setter Property="Opacity" Value="0" /> |
||||
</Style> |
</Style> |
||||
<Style Selector="RadioButton /template/ Ellipse#indeterminateMark"> |
|
||||
<Setter Property="IsVisible" Value="False"/> |
<Style Selector="RadioButton /template/ Ellipse#CheckGlyph"> |
||||
|
<Setter Property="Opacity" Value="0" /> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphStroke}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphFill}" /> |
||||
</Style> |
</Style> |
||||
<Style Selector="RadioButton:checked /template/ Ellipse#checkMark"> |
|
||||
<Setter Property="IsVisible" Value="True"/> |
|
||||
|
<!-- PointerOver State --> |
||||
|
<Style Selector="RadioButton:pointerover /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="(TextBlock.Foreground)" Value="{DynamicResource RadioButtonForegroundPointerOver}" /> |
||||
</Style> |
</Style> |
||||
<Style Selector="RadioButton:indeterminate /template/ Ellipse#indeterminateMark"> |
|
||||
<Setter Property="IsVisible" Value="True"/> |
<Style Selector="RadioButton:pointerover /template/ Border#RootBorder"> |
||||
|
<Setter Property="Background" Value="{DynamicResource RadioButtonBackgroundPointerOver}" /> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrushPointerOver}" /> |
||||
</Style> |
</Style> |
||||
<Style Selector="RadioButton:disabled /template/ Ellipse#border"> |
|
||||
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}"/> |
<Style Selector="RadioButton:pointerover /template/ Ellipse#OuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStrokePointerOver}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFillPointerOver}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:pointerover /template/ Ellipse#CheckOuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokePointerOver}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFillPointerOver}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:pointerover /template/ Ellipse#CheckGlyph"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphStrokePointerOver}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphFillPointerOver}" /> |
||||
|
</Style> |
||||
|
|
||||
|
|
||||
|
<!-- Pressed State --> |
||||
|
<Style Selector="RadioButton:pressed /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="(TextBlock.Foreground)" Value="{DynamicResource RadioButtonForegroundPressed}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:pressed /template/ Border#RootBorder"> |
||||
|
<Setter Property="Background" Value="{DynamicResource RadioButtonBackgroundPressed}" /> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrushPressed}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:pressed /template/ Ellipse#OuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStrokePressed}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFillPressed}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:pressed /template/ Ellipse#CheckOuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokePressed}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFillPressed}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:pressed /template/ Ellipse#CheckGlyph"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphStrokePressed}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphFillPressed}" /> |
||||
|
</Style> |
||||
|
|
||||
|
|
||||
|
<!-- Disabled State --> |
||||
|
<Style Selector="RadioButton:disabled /template/ ContentPresenter#PART_ContentPresenter"> |
||||
|
<Setter Property="(TextBlock.Foreground)" Value="{DynamicResource RadioButtonForegroundDisabled}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:disabled /template/ Border#RootBorder"> |
||||
|
<Setter Property="Background" Value="{DynamicResource RadioButtonBackgroundDisabled}" /> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource RadioButtonBorderBrushDisabled}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:disabled /template/ Ellipse#OuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseStrokeDisabled}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseFillDisabled}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:disabled /template/ Ellipse#CheckOuterEllipse"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonOuterEllipseCheckedStrokeDisabled}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonOuterEllipseCheckedFillDisabled}" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:disabled /template/ Ellipse#CheckGlyph"> |
||||
|
<Setter Property="Stroke" Value="{DynamicResource RadioButtonCheckGlyphFillDisabled}" /> |
||||
|
<Setter Property="Fill" Value="{DynamicResource RadioButtonCheckGlyphStrokeDisabled}" /> |
||||
|
</Style> |
||||
|
|
||||
|
|
||||
|
<!-- Checked State --> |
||||
|
<Style Selector="RadioButton:checked /template/ Ellipse#CheckGlyph"> |
||||
|
<Setter Property="Opacity" Value="1" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:checked /template/ Ellipse#OuterEllipse"> |
||||
|
<Setter Property="Opacity" Value="0" /> |
||||
|
</Style> |
||||
|
|
||||
|
<Style Selector="RadioButton:checked /template/ Ellipse#CheckOuterEllipse"> |
||||
|
<Setter Property="Opacity" Value="1" /> |
||||
</Style> |
</Style> |
||||
</Styles> |
</Styles> |
||||
|
|||||
@ -0,0 +1,57 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using Avalonia.Data.Core.Plugins; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Avalonia.Benchmarks.Data |
||||
|
{ |
||||
|
[MemoryDiagnoser, InProcess] |
||||
|
public class PropertyAccessorBenchmarks |
||||
|
{ |
||||
|
private readonly InpcPropertyAccessorPlugin _plugin = new InpcPropertyAccessorPlugin(); |
||||
|
private readonly TestObject _targetStrongRef = new TestObject(); |
||||
|
private readonly WeakReference<object> _targetWeakRef; |
||||
|
|
||||
|
public PropertyAccessorBenchmarks() |
||||
|
{ |
||||
|
_targetWeakRef = new WeakReference<object>(_targetStrongRef); |
||||
|
} |
||||
|
|
||||
|
[Benchmark] |
||||
|
public void InpcAccessor() |
||||
|
{ |
||||
|
_plugin.Start(_targetWeakRef, nameof(TestObject.Test)); |
||||
|
} |
||||
|
|
||||
|
private class TestObject : INotifyPropertyChanged |
||||
|
{ |
||||
|
private string _test; |
||||
|
|
||||
|
public string Test |
||||
|
{ |
||||
|
get => _test; |
||||
|
set |
||||
|
{ |
||||
|
if (_test == value) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
_test = value; |
||||
|
|
||||
|
OnPropertyChanged(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
|
||||
|
[NotifyPropertyChangedInvocator] |
||||
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
||||
|
{ |
||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
using Avalonia.Controls.Mixins; |
||||
|
using Avalonia.UnitTests; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Controls.UnitTests.Mixins |
||||
|
{ |
||||
|
public class PressedMixinTests |
||||
|
{ |
||||
|
private MouseTestHelper _mouse = new MouseTestHelper(); |
||||
|
|
||||
|
[Fact] |
||||
|
public void Selected_Class_Should_Not_Initially_Be_Added() |
||||
|
{ |
||||
|
var target = new TestControl(); |
||||
|
|
||||
|
Assert.Empty(target.Classes); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Setting_IsSelected_Should_Add_Selected_Class() |
||||
|
{ |
||||
|
var target = new TestControl(); |
||||
|
|
||||
|
_mouse.Down(target); |
||||
|
|
||||
|
Assert.Equal(new[] { ":pressed" }, target.Classes); |
||||
|
} |
||||
|
|
||||
|
private class TestControl : Control |
||||
|
{ |
||||
|
static TestControl() |
||||
|
{ |
||||
|
PressedMixin.Attach<TestControl>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue