Skip to content

Commit f998282

Browse files
committed
enhance: avalonia TextBox demo.
1 parent 5f2cbea commit f998282

File tree

7 files changed

+206
-127
lines changed

7 files changed

+206
-127
lines changed

src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@
2424
[ "DataGrid", "DataGridDemo", "Brush.DataGrid", "", "" ],
2525
[ "TreeView", "TreeViewDemo", "Brush.TreeView", "", "" ],
2626
[ "ListBox", "ListBoxDemo", "Brush.ListBox", "", "" ],
27-
[ "ListView", "ListViewDemo", "Brush.ListView", "", "" ],
2827
[ "GroupBox", "GroupBoxDemo", "Brush.GroupBox", "", "" ],
2928
[ "Menu", "MenuDemo", "Brush.ContextMenu", "", "" ],
30-
[ "RichTextBox", "RichTextBoxDemo", "Brush.RichTextBox", "", "" ],
31-
[ "FlowDocument", "FlowDocumentDemo", "Brush.WPFFlowDocument", "", "" ],
3229
[ "ToolBar", "ToolBarDemo", "Brush.ToolBar", "", "" ],
3330
[ "Border", "BorderDemo", "Brush.BorderElement", "", "" ],
3431
[ "Label", "LabelDemo", "Brush.Label", "", "" ],
@@ -121,7 +118,7 @@
121118
"group": false,
122119
"demoItemList": [
123120
[ "HatchBrushGenerator", "HatchBrushGeneratorDemo", "Brush.DataGenerator", "", "" ],
124-
[ "Morphing_Animation", "GeometryAnimationDemo", "Brush.Animation", "", "" ],
121+
[ "MorphingAnimation", "GeometryAnimationDemo", "Brush.Animation", "", "" ],
125122
[ "Effects", "EffectsDemo", "Brush.Effects", "", "" ]
126123
]
127124
}

src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/TextBoxDemo.axaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
Theme="{StaticResource TextBoxExtend}"
2222
Margin="0,32,0,0"
2323
Text="This is the content" />
24+
<TextBox hc:TitleElement.Title="This is the title"
25+
hc:InfoElement.ShowClearButton="True"
26+
Theme="{StaticResource TextBoxExtend}"
27+
Margin="0,32,0,0"
28+
Text="This is the content" />
2429
<TextBox hc:TitleElement.Title="This is the title"
2530
Theme="{StaticResource TextBoxExtend}"
2631
Margin="0,16,0,0"
@@ -59,6 +64,11 @@
5964
Theme="{StaticResource TextBoxExtend.Small}"
6065
Margin="0,32,0,0"
6166
Text="This is the content" />
67+
<TextBox hc:TitleElement.Title="This is the title"
68+
hc:InfoElement.ShowClearButton="True"
69+
Theme="{StaticResource TextBoxExtend.Small}"
70+
Margin="0,32,0,0"
71+
Text="This is the content" />
6272
<TextBox hc:TitleElement.Title="This is the title"
6373
Theme="{StaticResource TextBoxExtend.Small}"
6474
Margin="0,16,0,0"

src/Avalonia/HandyControl_Avalonia/Themes/Basic/Converters.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<hc:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
1111
<hc:DoubleExpandConverter x:Key="DoubleExpandConverter" />
1212
<hc:Double2GridLengthConverter x:Key="Double2GridLengthConverter" />
13+
<hc:ThicknessSplitConverter x:Key="ThicknessSplitConverter" />
1314
<avalonia:StringFormatConverter x:Key="StringFormatConverter" />
1415
<avalonia:MarginMultiplierConverter x:Key="LeftMarginConverter"
1516
Indent="16"

src/Avalonia/HandyControl_Avalonia/Themes/Styles/TextBox.axaml

Lines changed: 142 additions & 88 deletions
Large diffs are not rendered by default.

src/Avalonia/HandyControl_Avalonia/Tools/Converter/Double2GridLengthConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace HandyControl.Tools.Converter;
77

88
public class Double2GridLengthConverter : IValueConverter
99
{
10-
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
10+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1111
{
1212
if (value is not double doubleValue)
1313
{
@@ -22,7 +22,7 @@ public class Double2GridLengthConverter : IValueConverter
2222
return new GridLength(doubleValue);
2323
}
2424

25-
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
25+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
2626
{
2727
throw new NotSupportedException();
2828
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Globalization;
3+
using Avalonia;
4+
using Avalonia.Data.Converters;
5+
6+
namespace HandyControl.Tools.Converter;
7+
8+
public class ThicknessSplitConverter : IValueConverter
9+
{
10+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
11+
{
12+
if (value is not Thickness thickness || parameter is not string str)
13+
{
14+
return value;
15+
}
16+
17+
string[] arr = str.Split(',');
18+
19+
if (arr.Length != 4)
20+
{
21+
return thickness;
22+
}
23+
24+
return new Thickness(
25+
left: double.TryParse(arr[0], out double leftTimes) ? leftTimes * thickness.Left : thickness.Left,
26+
top: double.TryParse(arr[1], out double topTimes) ? topTimes * thickness.Top : thickness.Top,
27+
right: double.TryParse(arr[2], out double rightTimes) ? rightTimes * thickness.Right : thickness.Right,
28+
bottom: double.TryParse(arr[3], out double bottomTimes) ? bottomTimes * thickness.Bottom : thickness.Bottom
29+
);
30+
}
31+
32+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
33+
{
34+
throw new NotSupportedException();
35+
}
36+
}

src/Shared/HandyControl_Shared/Tools/Converter/ThicknessSplitConverter.cs

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,24 @@ public class ThicknessSplitConverter : IValueConverter
99
{
1010
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
1111
{
12-
if (value is Thickness thickness)
12+
if (value is not Thickness thickness || parameter is not string str)
1313
{
14-
if (parameter is string str)
15-
{
16-
var arr = str.Split(',');
17-
18-
if (arr.Length != 4)
19-
{
20-
return thickness;
21-
}
22-
23-
var result = new Thickness(thickness.Left, thickness.Top, thickness.Right, thickness.Bottom);
24-
25-
if (double.TryParse(arr[0], out double leftTimes))
26-
{
27-
result.Left = leftTimes * thickness.Left;
28-
}
29-
30-
if (double.TryParse(arr[1], out double topTimes))
31-
{
32-
result.Top = topTimes * thickness.Top;
33-
}
34-
35-
if (double.TryParse(arr[2], out double rightTimes))
36-
{
37-
result.Right = rightTimes * thickness.Right;
38-
}
14+
return value;
15+
}
3916

40-
if (double.TryParse(arr[3], out double bottomTimes))
41-
{
42-
result.Bottom = bottomTimes * thickness.Bottom;
43-
}
17+
var arr = str.Split(',');
4418

45-
return result;
46-
}
19+
if (arr.Length != 4)
20+
{
21+
return thickness;
4722
}
48-
return value;
23+
24+
return new Thickness(
25+
left: double.TryParse(arr[0], out double leftTimes) ? leftTimes * thickness.Left : thickness.Left,
26+
top: double.TryParse(arr[1], out double topTimes) ? topTimes * thickness.Top : thickness.Top,
27+
right: double.TryParse(arr[2], out double rightTimes) ? rightTimes * thickness.Right : thickness.Right,
28+
bottom: double.TryParse(arr[3], out double bottomTimes) ? bottomTimes * thickness.Bottom : thickness.Bottom
29+
);
4930
}
5031

5132
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

0 commit comments

Comments
 (0)