chore: add avalonia Expander demo.

This commit is contained in:
NaBian committed 2025-01-26 14:16:12 +08:00
1 parent 840493b375
commit 99c1effd84
7 files changed
+672 -13

No files matched your search

@@ -0,0 +1,341 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
x:Class="HandyControlDemo.UserControl.ExpanderDemo">
<ScrollViewer>
<hc:UniformSpacingPanel Margin="32"
Orientation="Vertical"
Spacing="32">
<hc:UniformSpacingPanel Spacing="32"
ChildWrapping="Wrap"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<hc:UniformSpacingPanel Orientation="Vertical"
Spacing="32">
<StackPanel Width="240">
<Expander Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
<Expander Margin="0,4,0,0"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
<Expander Margin="0,4,0,0"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
<Expander Margin="0,4,0,0"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
</StackPanel>
<StackPanel Width="240">
<Expander Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
<Expander Margin="0,4,0,0"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
<Expander Margin="0,4,0,0"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
<Expander Margin="0,4,0,0"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
</StackPanel>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="32"
ChildWrapping="Wrap">
<StackPanel Height="240"
Orientation="Horizontal">
<Expander Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
<Expander Margin="4,0,0,0"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
<Expander Margin="4,0,0,0"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
<Expander Margin="4,0,0,0"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
</StackPanel>
<StackPanel Height="240"
Orientation="Horizontal">
<Expander Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
<Expander Margin="4,0,0,0"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
<Expander Margin="4,0,0,0"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
<Expander Margin="4,0,0,0"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
</StackPanel>
</hc:UniformSpacingPanel>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="32"
ChildWrapping="Wrap"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<hc:UniformSpacingPanel Orientation="Vertical"
Spacing="32">
<StackPanel Width="240">
<Expander Theme="{StaticResource Expander.Small}"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="0,4,0,0"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="0,4,0,0"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="0,4,0,0"
Header="Title">
<Border Height="100"
BorderThickness="1,0,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,0,4,4" />
</Expander>
</StackPanel>
<StackPanel Width="240">
<Expander Theme="{StaticResource Expander.Small}"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="0,4,0,0"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="0,4,0,0"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="0,4,0,0"
Header="Title"
ExpandDirection="Up">
<Border Height="100"
BorderThickness="1,1,1,0"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,4,0,0" />
</Expander>
</StackPanel>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="32"
ChildWrapping="Wrap">
<StackPanel Height="240"
Orientation="Horizontal">
<Expander Theme="{StaticResource Expander.Small}"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="4,0,0,0"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="4,0,0,0"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="4,0,0,0"
Header="Title"
ExpandDirection="Left">
<Border Width="100"
BorderThickness="1,1,0,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="4,0,0,4" />
</Expander>
</StackPanel>
<StackPanel Height="240"
Orientation="Horizontal">
<Expander Theme="{StaticResource Expander.Small}"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="4,0,0,0"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="4,0,0,0"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
<Expander Theme="{StaticResource Expander.Small}"
Margin="4,0,0,0"
Header="Title"
ExpandDirection="Right">
<Border Width="100"
BorderThickness="0,1,1,1"
BorderBrush="{DynamicResource BorderBrush}"
Background="{DynamicResource RegionBrush}"
CornerRadius="0,4,4,0" />
</Expander>
</StackPanel>
</hc:UniformSpacingPanel>
</hc:UniformSpacingPanel>
</hc:UniformSpacingPanel>
</ScrollViewer>
</UserControl>
@@ -0,0 +1,10 @@
namespace HandyControlDemo.UserControl;
public partial class ExpanderDemo : Avalonia.Controls.UserControl
{
public ExpanderDemo()
{
InitializeComponent();
}
}
@@ -6,5 +6,6 @@
<converter:BorderCircularConverter x:Key="BorderCircularConverter" />
<converter:BorderCircularClipConverter x:Key="BorderCircularClipConverter" />
<converter:GeometrySpacingConverter x:Key="GeometrySpacingConverter" />
<converter:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
</ResourceDictionary>
@@ -0,0 +1,266 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="clr-namespace:HandyControl.Controls">
<ControlTemplate x:Key="ExpanderLeftTemplate"
TargetType="Expander">
<Grid ColumnDefinitions="*, Auto">
<ToggleButton Grid.Column="1"
VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch"
Focusable="False"
Padding="0,0,0,10"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
MinWidth="{TemplateBinding MinWidth}"
Theme="{StaticResource ToggleButtonCustom}">
<LayoutTransformControl>
<LayoutTransformControl.LayoutTransform>
<RotateTransform Angle="-90" />
</LayoutTransformControl.LayoutTransform>
<Grid ColumnDefinitions="*,30">
<ContentPresenter Content="{TemplateBinding Header}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<Path x:Name="PathArrow"
IsHitTestVisible="False"
Grid.Column="1"
Stretch="Uniform"
Fill="{TemplateBinding Foreground}"
Width="12"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="Center" />
</Grid>
</LayoutTransformControl>
</ToggleButton>
<ContentPresenter Name="PART_ContentPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Column="0" />
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ExpanderUpTemplate"
TargetType="Expander">
<Grid RowDefinitions="*,Auto">
<ToggleButton Grid.Row="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Focusable="False"
Padding="10,0,0,0"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
MinHeight="{TemplateBinding MinHeight}"
Theme="{StaticResource ToggleButtonCustom}">
<Grid ColumnDefinitions="*,30">
<ContentPresenter Content="{TemplateBinding Header}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<Path x:Name="PathArrow"
IsHitTestVisible="False"
Grid.Column="1"
Stretch="Uniform"
Fill="{TemplateBinding Foreground}"
Width="12"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="Center" />
</Grid>
</ToggleButton>
<ContentPresenter x:Name="PART_ContentPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Row="0" />
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ExpanderRightTemplate"
TargetType="Expander">
<Grid ColumnDefinitions="Auto,*">
<ToggleButton VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch"
Focusable="False"
Padding="0,0,0,10"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
MinWidth="{TemplateBinding MinWidth}"
Theme="{StaticResource ToggleButtonCustom}">
<LayoutTransformControl>
<LayoutTransformControl.LayoutTransform>
<RotateTransform Angle="-90" />
</LayoutTransformControl.LayoutTransform>
<Grid ColumnDefinitions="*,30">
<ContentPresenter Content="{TemplateBinding Header}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<Path x:Name="PathArrow"
IsHitTestVisible="False"
Grid.Column="1"
Stretch="Uniform"
Fill="{TemplateBinding Foreground}"
Width="12"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="Center" />
</Grid>
</LayoutTransformControl>
</ToggleButton>
<ContentPresenter x:Name="PART_ContentPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Column="1" />
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ExpanderDownTemplate"
TargetType="Expander">
<Grid RowDefinitions="Auto,*">
<ToggleButton HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Focusable="False"
Padding="10,0,0,0"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Foreground="{TemplateBinding Foreground}"
IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
MinHeight="{TemplateBinding MinHeight}"
Theme="{StaticResource ToggleButtonCustom}">
<Grid ColumnDefinitions="*,30">
<ContentPresenter Content="{TemplateBinding Header}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<Path x:Name="PathArrow"
IsHitTestVisible="False"
Grid.Column="1"
Stretch="Uniform"
Fill="{TemplateBinding Foreground}"
Width="12"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="Center" />
</Grid>
</ToggleButton>
<ContentPresenter x:Name="PART_ContentPresenter"
IsVisible="{TemplateBinding IsExpanded}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Row="1" />
</Grid>
</ControlTemplate>
<ControlTheme x:Key="ExpanderBaseStyle"
TargetType="Expander">
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
<Setter Property="HorizontalContentAlignment"
Value="Left" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="MinHeight"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="MinWidth"
Value="{StaticResource DefaultControlHeight}" />
<Setter Property="hc:BorderElement.CornerRadius"
Value="{StaticResource DefaultCornerRadius}" />
<Style Selector="^:left">
<Setter Property="Template"
Value="{StaticResource ExpanderLeftTemplate}" />
</Style>
<Style Selector="^:up">
<Setter Property="Template"
Value="{StaticResource ExpanderUpTemplate}" />
</Style>
<Style Selector="^:right">
<Setter Property="Template"
Value="{StaticResource ExpanderRightTemplate}" />
</Style>
<Style Selector="^:down">
<Setter Property="Template"
Value="{StaticResource ExpanderDownTemplate}" />
</Style>
<Style Selector="^[IsExpanded=True]">
<Style Selector="^:left /template/ ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusSplitConverter}, ConverterParameter='0,1,1,0'}">
</Setter>
</Style>
<Style Selector="^:up /template/ ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusSplitConverter}, ConverterParameter='0,0,1,1'}">
</Setter>
</Style>
<Style Selector="^:right /template/ ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusSplitConverter}, ConverterParameter='1,0,0,1'}">
</Setter>
</Style>
<Style Selector="^:down /template/ ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusSplitConverter}, ConverterParameter='1,1,0,0'}">
</Setter>
</Style>
<Style Selector="^:left /template/ Path#PathArrow, ^:up /template/ Path#PathArrow">
<Setter Property="Data"
Value="{StaticResource DownGeometry}" />
</Style>
<Style Selector="^:right /template/ Path#PathArrow, ^:down /template/ Path#PathArrow">
<Setter Property="Data"
Value="{StaticResource UpGeometry}" />
</Style>
</Style>
<Style Selector="^[IsExpanded=False]">
<Style Selector="^ /template/ ToggleButton">
<Setter Property="hc:BorderElement.CornerRadius"
Value="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource CornerRadiusSplitConverter}, ConverterParameter='1,1,1,1'}">
</Setter>
</Style>
<Style Selector="^:left /template/ Path#PathArrow, ^:up /template/ Path#PathArrow">
<Setter Property="Data"
Value="{StaticResource UpGeometry}" />
</Style>
<Style Selector="^:right /template/ Path#PathArrow, ^:down /template/ Path#PathArrow">
<Setter Property="Data"
Value="{StaticResource DownGeometry}" />
</Style>
</Style>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type Expander}"
BasedOn="{StaticResource ExpanderBaseStyle}"
TargetType="Expander" />
<ControlTheme x:Key="Expander.Small"
BasedOn="{StaticResource ExpanderBaseStyle}"
TargetType="Expander">
<Setter Property="MinHeight"
Value="20" />
<Setter Property="MinWidth"
Value="20" />
</ControlTheme>
</ResourceDictionary>
@@ -33,6 +33,7 @@
<MergeResourceInclude Source="/Themes/Styles/ListBox.axaml" />
<MergeResourceInclude Source="/Themes/Styles/Label.axaml" />
<MergeResourceInclude Source="/Themes/Styles/Slider.axaml" />
<MergeResourceInclude Source="/Themes/Styles/Expander.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>
@@ -0,0 +1,37 @@
using System;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
namespace HandyControl.Tools.Converter;
public class CornerRadiusSplitConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not CornerRadius cornerRadius)
{
return value;
}
if (parameter is not string str)
{
return value;
}
string[] arr = str.Split(',');
if (arr.Length != 4)
{
return cornerRadius;
}
return new CornerRadius(
arr[0].Trim().Equals("1") ? cornerRadius.TopLeft : 0,
arr[1].Trim().Equals("1") ? cornerRadius.TopRight : 0,
arr[2].Trim().Equals("1") ? cornerRadius.BottomRight : 0,
arr[3].Trim().Equals("1") ? cornerRadius.BottomLeft : 0);
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>
throw new NotImplementedException();
}
@@ -9,21 +9,24 @@ public class CornerRadiusSplitConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is CornerRadius cornerRadius)
if (value is not CornerRadius cornerRadius)
{
if (parameter is string str)
{
var arr = str.Split(',');
if (arr.Length != 4) return cornerRadius;
return new CornerRadius(
arr[0].Equals("1") ? cornerRadius.TopLeft : 0,
arr[1].Equals("1") ? cornerRadius.TopRight : 0,
arr[2].Equals("1") ? cornerRadius.BottomRight : 0,
arr[3].Equals("1") ? cornerRadius.BottomLeft : 0);
}
return value;
}
return value;
if (parameter is not string str)
{
return value;
}
var arr = str.Split(',');
if (arr.Length != 4) return cornerRadius;
return new CornerRadius(
arr[0].Trim().Equals("1") ? cornerRadius.TopLeft : 0,
arr[1].Trim().Equals("1") ? cornerRadius.TopRight : 0,
arr[2].Trim().Equals("1") ? cornerRadius.BottomRight : 0,
arr[3].Trim().Equals("1") ? cornerRadius.BottomLeft : 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)