enhance: avalonia TextBox demo.
This commit is contained in:
1 parent
5f2cbeab9d
commit
f9982820a9
7 files changed
+208
-129
No files matched your search
@@ -24,11 +24,8 @@
|
|||||||
[ "DataGrid", "DataGridDemo", "Brush.DataGrid", "", "" ],
|
[ "DataGrid", "DataGridDemo", "Brush.DataGrid", "", "" ],
|
||||||
[ "TreeView", "TreeViewDemo", "Brush.TreeView", "", "" ],
|
[ "TreeView", "TreeViewDemo", "Brush.TreeView", "", "" ],
|
||||||
[ "ListBox", "ListBoxDemo", "Brush.ListBox", "", "" ],
|
[ "ListBox", "ListBoxDemo", "Brush.ListBox", "", "" ],
|
||||||
[ "ListView", "ListViewDemo", "Brush.ListView", "", "" ],
|
|
||||||
[ "GroupBox", "GroupBoxDemo", "Brush.GroupBox", "", "" ],
|
[ "GroupBox", "GroupBoxDemo", "Brush.GroupBox", "", "" ],
|
||||||
[ "Menu", "MenuDemo", "Brush.ContextMenu", "", "" ],
|
[ "Menu", "MenuDemo", "Brush.ContextMenu", "", "" ],
|
||||||
[ "RichTextBox", "RichTextBoxDemo", "Brush.RichTextBox", "", "" ],
|
|
||||||
[ "FlowDocument", "FlowDocumentDemo", "Brush.WPFFlowDocument", "", "" ],
|
|
||||||
[ "ToolBar", "ToolBarDemo", "Brush.ToolBar", "", "" ],
|
[ "ToolBar", "ToolBarDemo", "Brush.ToolBar", "", "" ],
|
||||||
[ "Border", "BorderDemo", "Brush.BorderElement", "", "" ],
|
[ "Border", "BorderDemo", "Brush.BorderElement", "", "" ],
|
||||||
[ "Label", "LabelDemo", "Brush.Label", "", "" ],
|
[ "Label", "LabelDemo", "Brush.Label", "", "" ],
|
||||||
@@ -121,7 +118,7 @@
|
|||||||
"group": false,
|
"group": false,
|
||||||
"demoItemList": [
|
"demoItemList": [
|
||||||
[ "HatchBrushGenerator", "HatchBrushGeneratorDemo", "Brush.DataGenerator", "", "" ],
|
[ "HatchBrushGenerator", "HatchBrushGeneratorDemo", "Brush.DataGenerator", "", "" ],
|
||||||
[ "Morphing_Animation", "GeometryAnimationDemo", "Brush.Animation", "", "" ],
|
[ "MorphingAnimation", "GeometryAnimationDemo", "Brush.Animation", "", "" ],
|
||||||
[ "Effects", "EffectsDemo", "Brush.Effects", "", "" ]
|
[ "Effects", "EffectsDemo", "Brush.Effects", "", "" ]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,11 @@
|
|||||||
Theme="{StaticResource TextBoxExtend}"
|
Theme="{StaticResource TextBoxExtend}"
|
||||||
Margin="0,32,0,0"
|
Margin="0,32,0,0"
|
||||||
Text="This is the content" />
|
Text="This is the content" />
|
||||||
|
<TextBox hc:TitleElement.Title="This is the title"
|
||||||
|
hc:InfoElement.ShowClearButton="True"
|
||||||
|
Theme="{StaticResource TextBoxExtend}"
|
||||||
|
Margin="0,32,0,0"
|
||||||
|
Text="This is the content" />
|
||||||
<TextBox hc:TitleElement.Title="This is the title"
|
<TextBox hc:TitleElement.Title="This is the title"
|
||||||
Theme="{StaticResource TextBoxExtend}"
|
Theme="{StaticResource TextBoxExtend}"
|
||||||
Margin="0,16,0,0"
|
Margin="0,16,0,0"
|
||||||
@@ -59,6 +64,11 @@
|
|||||||
Theme="{StaticResource TextBoxExtend.Small}"
|
Theme="{StaticResource TextBoxExtend.Small}"
|
||||||
Margin="0,32,0,0"
|
Margin="0,32,0,0"
|
||||||
Text="This is the content" />
|
Text="This is the content" />
|
||||||
|
<TextBox hc:TitleElement.Title="This is the title"
|
||||||
|
hc:InfoElement.ShowClearButton="True"
|
||||||
|
Theme="{StaticResource TextBoxExtend.Small}"
|
||||||
|
Margin="0,32,0,0"
|
||||||
|
Text="This is the content" />
|
||||||
<TextBox hc:TitleElement.Title="This is the title"
|
<TextBox hc:TitleElement.Title="This is the title"
|
||||||
Theme="{StaticResource TextBoxExtend.Small}"
|
Theme="{StaticResource TextBoxExtend.Small}"
|
||||||
Margin="0,16,0,0"
|
Margin="0,16,0,0"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<hc:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
|
<hc:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
|
||||||
<hc:DoubleExpandConverter x:Key="DoubleExpandConverter" />
|
<hc:DoubleExpandConverter x:Key="DoubleExpandConverter" />
|
||||||
<hc:Double2GridLengthConverter x:Key="Double2GridLengthConverter" />
|
<hc:Double2GridLengthConverter x:Key="Double2GridLengthConverter" />
|
||||||
|
<hc:ThicknessSplitConverter x:Key="ThicknessSplitConverter" />
|
||||||
<avalonia:StringFormatConverter x:Key="StringFormatConverter" />
|
<avalonia:StringFormatConverter x:Key="StringFormatConverter" />
|
||||||
<avalonia:MarginMultiplierConverter x:Key="LeftMarginConverter"
|
<avalonia:MarginMultiplierConverter x:Key="LeftMarginConverter"
|
||||||
Indent="16"
|
Indent="16"
|
||||||
|
|||||||
@@ -121,50 +121,77 @@
|
|||||||
TextTrimming="CharacterEllipsis"
|
TextTrimming="CharacterEllipsis"
|
||||||
Text="{Binding Path=(hc:TitleElement.Title), RelativeSource={RelativeSource TemplatedParent}}" />
|
Text="{Binding Path=(hc:TitleElement.Title), RelativeSource={RelativeSource TemplatedParent}}" />
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<Border x:Name="border"
|
<Grid Grid.Row="1"
|
||||||
Grid.Row="1"
|
ColumnDefinitions="*,Auto">
|
||||||
CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
|
<Border x:Name="border"
|
||||||
BorderBrush="{TemplateBinding BorderBrush}"
|
Grid.ColumnSpan="2"
|
||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
|
||||||
Background="{TemplateBinding Background}" />
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
<TextBlock Grid.Row="1"
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
Background="{TemplateBinding Background}" />
|
||||||
Margin="{TemplateBinding Padding}"
|
<TextBlock Grid.Column="0"
|
||||||
IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
HorizontalAlignment="Stretch"
|
Margin="{TemplateBinding Padding}"
|
||||||
Theme="{StaticResource TextBlockDefaultThiLight}"
|
IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}"
|
||||||
Text="{TemplateBinding Watermark}" />
|
HorizontalAlignment="Stretch"
|
||||||
<ScrollViewer Name="PART_ScrollViewer"
|
Theme="{StaticResource TextBlockDefaultThiLight}"
|
||||||
Grid.Row="1"
|
Text="{TemplateBinding Watermark}" />
|
||||||
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
<ScrollViewer Grid.Column="0"
|
||||||
BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"
|
Name="PART_ScrollViewer"
|
||||||
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
||||||
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"
|
||||||
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
||||||
<TextPresenter Name="PART_TextPresenter"
|
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
||||||
Margin="{TemplateBinding Padding}"
|
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
<TextPresenter Name="PART_TextPresenter"
|
||||||
CaretBlinkInterval="{TemplateBinding CaretBlinkInterval}"
|
Margin="{TemplateBinding Padding}"
|
||||||
CaretBrush="{TemplateBinding CaretBrush}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
CaretIndex="{TemplateBinding CaretIndex}"
|
CaretBlinkInterval="{TemplateBinding CaretBlinkInterval}"
|
||||||
LineHeight="{TemplateBinding LineHeight}"
|
CaretBrush="{TemplateBinding CaretBrush}"
|
||||||
LetterSpacing="{TemplateBinding LetterSpacing}"
|
CaretIndex="{TemplateBinding CaretIndex}"
|
||||||
PasswordChar="{TemplateBinding PasswordChar}"
|
LineHeight="{TemplateBinding LineHeight}"
|
||||||
RevealPassword="{TemplateBinding RevealPassword}"
|
LetterSpacing="{TemplateBinding LetterSpacing}"
|
||||||
SelectionBrush="{TemplateBinding SelectionBrush}"
|
PasswordChar="{TemplateBinding PasswordChar}"
|
||||||
SelectionEnd="{TemplateBinding SelectionEnd}"
|
RevealPassword="{TemplateBinding RevealPassword}"
|
||||||
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
|
SelectionBrush="{TemplateBinding SelectionBrush}"
|
||||||
SelectionStart="{TemplateBinding SelectionStart}"
|
SelectionEnd="{TemplateBinding SelectionEnd}"
|
||||||
Text="{TemplateBinding Text,Mode=TwoWay}"
|
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
|
||||||
TextAlignment="{TemplateBinding TextAlignment}"
|
SelectionStart="{TemplateBinding SelectionStart}"
|
||||||
TextWrapping="{TemplateBinding TextWrapping}" />
|
Text="{TemplateBinding Text,Mode=TwoWay}"
|
||||||
<ScrollViewer.Styles>
|
TextAlignment="{TemplateBinding TextAlignment}"
|
||||||
<Style Selector="ScrollContentPresenter#PART_ContentPresenter">
|
TextWrapping="{TemplateBinding TextWrapping}" />
|
||||||
<Setter Property="Cursor"
|
<ScrollViewer.Styles>
|
||||||
Value="IBeam" />
|
<Style Selector="ScrollContentPresenter#PART_ContentPresenter">
|
||||||
</Style>
|
<Setter Property="Cursor"
|
||||||
</ScrollViewer.Styles>
|
Value="IBeam" />
|
||||||
</ScrollViewer>
|
</Style>
|
||||||
|
</ScrollViewer.Styles>
|
||||||
|
</ScrollViewer>
|
||||||
|
<Button HorizontalContentAlignment="Left"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
hc:IconElement.Width="14"
|
||||||
|
Command="{Binding $parent[TextBox].Clear}"
|
||||||
|
Name="ButtonClear"
|
||||||
|
Focusable="False"
|
||||||
|
Grid.Column="1"
|
||||||
|
Theme="{StaticResource ButtonIcon}"
|
||||||
|
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='0,0,1,0'}"
|
||||||
|
hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"
|
||||||
|
Foreground="{Binding BorderBrush,ElementName=border}">
|
||||||
|
<Button.IsVisible>
|
||||||
|
<MultiBinding Converter="{x:Static BoolConverters.And}">
|
||||||
|
<Binding RelativeSource="{RelativeSource TemplatedParent}"
|
||||||
|
Path="IsPointerOver" />
|
||||||
|
<Binding RelativeSource="{RelativeSource TemplatedParent}"
|
||||||
|
Path="(hc:InfoElement.ShowClearButton)" />
|
||||||
|
<Binding RelativeSource="{RelativeSource TemplatedParent}"
|
||||||
|
Path="IsReadOnly"
|
||||||
|
Converter="{x:Static BoolConverters.Not}" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Button.IsVisible>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|
||||||
@@ -191,50 +218,77 @@
|
|||||||
TextTrimming="CharacterEllipsis"
|
TextTrimming="CharacterEllipsis"
|
||||||
Text="{Binding Path=(hc:TitleElement.Title), RelativeSource={RelativeSource TemplatedParent}}" />
|
Text="{Binding Path=(hc:TitleElement.Title), RelativeSource={RelativeSource TemplatedParent}}" />
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<Border x:Name="border"
|
<Grid Grid.Column="1"
|
||||||
Grid.Column="1"
|
ColumnDefinitions="*,Auto">
|
||||||
CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
|
<Border x:Name="border"
|
||||||
BorderBrush="{TemplateBinding BorderBrush}"
|
Grid.ColumnSpan="2"
|
||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
|
||||||
Background="{TemplateBinding Background}" />
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
<TextBlock Grid.Column="1"
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
Background="{TemplateBinding Background}" />
|
||||||
Margin="{TemplateBinding Padding}"
|
<TextBlock Grid.Column="0"
|
||||||
IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
HorizontalAlignment="Stretch"
|
Margin="{TemplateBinding Padding}"
|
||||||
Theme="{StaticResource TextBlockDefaultThiLight}"
|
IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}"
|
||||||
Text="{TemplateBinding Watermark}" />
|
HorizontalAlignment="Stretch"
|
||||||
<ScrollViewer Name="PART_ScrollViewer"
|
Theme="{StaticResource TextBlockDefaultThiLight}"
|
||||||
Grid.Column="1"
|
Text="{TemplateBinding Watermark}" />
|
||||||
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
<ScrollViewer Grid.Column="0"
|
||||||
BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"
|
Name="PART_ScrollViewer"
|
||||||
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
||||||
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
BringIntoViewOnFocusChange="{TemplateBinding (ScrollViewer.BringIntoViewOnFocusChange)}"
|
||||||
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
||||||
<TextPresenter Name="PART_TextPresenter"
|
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
||||||
Margin="{TemplateBinding Padding}"
|
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
<TextPresenter Name="PART_TextPresenter"
|
||||||
CaretBlinkInterval="{TemplateBinding CaretBlinkInterval}"
|
Margin="{TemplateBinding Padding}"
|
||||||
CaretBrush="{TemplateBinding CaretBrush}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
CaretIndex="{TemplateBinding CaretIndex}"
|
CaretBlinkInterval="{TemplateBinding CaretBlinkInterval}"
|
||||||
LineHeight="{TemplateBinding LineHeight}"
|
CaretBrush="{TemplateBinding CaretBrush}"
|
||||||
LetterSpacing="{TemplateBinding LetterSpacing}"
|
CaretIndex="{TemplateBinding CaretIndex}"
|
||||||
PasswordChar="{TemplateBinding PasswordChar}"
|
LineHeight="{TemplateBinding LineHeight}"
|
||||||
RevealPassword="{TemplateBinding RevealPassword}"
|
LetterSpacing="{TemplateBinding LetterSpacing}"
|
||||||
SelectionBrush="{TemplateBinding SelectionBrush}"
|
PasswordChar="{TemplateBinding PasswordChar}"
|
||||||
SelectionEnd="{TemplateBinding SelectionEnd}"
|
RevealPassword="{TemplateBinding RevealPassword}"
|
||||||
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
|
SelectionBrush="{TemplateBinding SelectionBrush}"
|
||||||
SelectionStart="{TemplateBinding SelectionStart}"
|
SelectionEnd="{TemplateBinding SelectionEnd}"
|
||||||
Text="{TemplateBinding Text,Mode=TwoWay}"
|
SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}"
|
||||||
TextAlignment="{TemplateBinding TextAlignment}"
|
SelectionStart="{TemplateBinding SelectionStart}"
|
||||||
TextWrapping="{TemplateBinding TextWrapping}" />
|
Text="{TemplateBinding Text,Mode=TwoWay}"
|
||||||
<ScrollViewer.Styles>
|
TextAlignment="{TemplateBinding TextAlignment}"
|
||||||
<Style Selector="ScrollContentPresenter#PART_ContentPresenter">
|
TextWrapping="{TemplateBinding TextWrapping}" />
|
||||||
<Setter Property="Cursor"
|
<ScrollViewer.Styles>
|
||||||
Value="IBeam" />
|
<Style Selector="ScrollContentPresenter#PART_ContentPresenter">
|
||||||
</Style>
|
<Setter Property="Cursor"
|
||||||
</ScrollViewer.Styles>
|
Value="IBeam" />
|
||||||
</ScrollViewer>
|
</Style>
|
||||||
|
</ScrollViewer.Styles>
|
||||||
|
</ScrollViewer>
|
||||||
|
<Button HorizontalContentAlignment="Left"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
hc:IconElement.Width="14"
|
||||||
|
Command="{Binding $parent[TextBox].Clear}"
|
||||||
|
Name="ButtonClear"
|
||||||
|
Focusable="False"
|
||||||
|
Grid.Column="1"
|
||||||
|
Theme="{StaticResource ButtonIcon}"
|
||||||
|
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='0,0,1,0'}"
|
||||||
|
hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"
|
||||||
|
Foreground="{Binding BorderBrush,ElementName=border}">
|
||||||
|
<Button.IsVisible>
|
||||||
|
<MultiBinding Converter="{x:Static BoolConverters.And}">
|
||||||
|
<Binding RelativeSource="{RelativeSource TemplatedParent}"
|
||||||
|
Path="IsPointerOver" />
|
||||||
|
<Binding RelativeSource="{RelativeSource TemplatedParent}"
|
||||||
|
Path="(hc:InfoElement.ShowClearButton)" />
|
||||||
|
<Binding RelativeSource="{RelativeSource TemplatedParent}"
|
||||||
|
Path="IsReadOnly"
|
||||||
|
Converter="{x:Static BoolConverters.Not}" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Button.IsVisible>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace HandyControl.Tools.Converter;
|
|||||||
|
|
||||||
public class Double2GridLengthConverter : IValueConverter
|
public class Double2GridLengthConverter : IValueConverter
|
||||||
{
|
{
|
||||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
if (value is not double doubleValue)
|
if (value is not double doubleValue)
|
||||||
{
|
{
|
||||||
@@ -22,7 +22,7 @@ public class Double2GridLengthConverter : IValueConverter
|
|||||||
return new GridLength(doubleValue);
|
return new GridLength(doubleValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace HandyControl.Tools.Converter;
|
||||||
|
|
||||||
|
public class ThicknessSplitConverter : IValueConverter
|
||||||
|
{
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is not Thickness thickness || parameter is not string str)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] arr = str.Split(',');
|
||||||
|
|
||||||
|
if (arr.Length != 4)
|
||||||
|
{
|
||||||
|
return thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Thickness(
|
||||||
|
left: double.TryParse(arr[0], out double leftTimes) ? leftTimes * thickness.Left : thickness.Left,
|
||||||
|
top: double.TryParse(arr[1], out double topTimes) ? topTimes * thickness.Top : thickness.Top,
|
||||||
|
right: double.TryParse(arr[2], out double rightTimes) ? rightTimes * thickness.Right : thickness.Right,
|
||||||
|
bottom: double.TryParse(arr[3], out double bottomTimes) ? bottomTimes * thickness.Bottom : thickness.Bottom
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,43 +9,24 @@ public class ThicknessSplitConverter : IValueConverter
|
|||||||
{
|
{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
if (value is Thickness thickness)
|
if (value is not Thickness thickness || parameter is not string str)
|
||||||
{
|
{
|
||||||
if (parameter is string str)
|
return value;
|
||||||
{
|
|
||||||
var arr = str.Split(',');
|
|
||||||
|
|
||||||
if (arr.Length != 4)
|
|
||||||
{
|
|
||||||
return thickness;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = new Thickness(thickness.Left, thickness.Top, thickness.Right, thickness.Bottom);
|
|
||||||
|
|
||||||
if (double.TryParse(arr[0], out double leftTimes))
|
|
||||||
{
|
|
||||||
result.Left = leftTimes * thickness.Left;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (double.TryParse(arr[1], out double topTimes))
|
|
||||||
{
|
|
||||||
result.Top = topTimes * thickness.Top;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (double.TryParse(arr[2], out double rightTimes))
|
|
||||||
{
|
|
||||||
result.Right = rightTimes * thickness.Right;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (double.TryParse(arr[3], out double bottomTimes))
|
|
||||||
{
|
|
||||||
result.Bottom = bottomTimes * thickness.Bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
|
var arr = str.Split(',');
|
||||||
|
|
||||||
|
if (arr.Length != 4)
|
||||||
|
{
|
||||||
|
return thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Thickness(
|
||||||
|
left: double.TryParse(arr[0], out double leftTimes) ? leftTimes * thickness.Left : thickness.Left,
|
||||||
|
top: double.TryParse(arr[1], out double topTimes) ? topTimes * thickness.Top : thickness.Top,
|
||||||
|
right: double.TryParse(arr[2], out double rightTimes) ? rightTimes * thickness.Right : thickness.Right,
|
||||||
|
bottom: double.TryParse(arr[3], out double bottomTimes) ? bottomTimes * thickness.Bottom : thickness.Bottom
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
|||||||
Reference in new issue
Block a user