Skip to content

Commit 2fb1212

Browse files
committed
chore: add avalonia basic TextBox demo.
1 parent 752b151 commit 2fb1212

File tree

20 files changed

+677
-48
lines changed

20 files changed

+677
-48
lines changed

README-cn.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
### 找工作
2-
我有一个朋友,9 年工作经验,github 主页:https://github.com/DingpingZhang 目前在找上海的工作。他熟悉设计模式并具有大型客户端架构经验,技术栈涉及:python、wpf、pg、react,有意向可联系邮箱:[email protected]
3-
41
## 友情链接
52

63
[SimpleFactoryGenerator](https://github.com/DingpingZhang/SimpleFactoryGenerator) - A simple factory source generator that enables the pattern to not violate the open-close principle.

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
### 找工作
2-
我有一个朋友,9 年工作经验,github 主页:https://github.com/DingpingZhang 目前在找上海的工作。他熟悉设计模式并具有大型客户端架构经验,技术栈涉及:python、wpf、pg、react,有意向可联系邮箱:[email protected]
3-
41
## Blogroll
52

63
[SimpleFactoryGenerator](https://github.com/DingpingZhang/SimpleFactoryGenerator) - A simple factory source generator that enables the pattern to not violate the open-close principle.

src/Avalonia/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
33
<Nullable>enable</Nullable>
4-
<AvaloniaVersion>11.1.1</AvaloniaVersion>
4+
<AvaloniaVersion>11.3.2</AvaloniaVersion>
55
</PropertyGroup>
66
</Project>

src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[ "ScrollViewer", "NativeScrollViewerDemo", "Brush.ScrollBox", "", "" ],
1414
[ "Slider", "SliderDemo", "Brush.Slider", "", "" ],
1515
[ "TextBlock", "TextBlockDemo", "Brush.TextBlock", "", "" ],
16-
[ "TextBox", "NativeTextBoxDemo", "Brush.TextBox", "", "" ],
16+
[ "TextBox", "TextBoxDemo", "Brush.TextBox", "", "" ],
1717
[ "ComboBox", "NativeComboBoxDemo", "Brush.ComboBox", "", "" ],
1818
[ "PasswordBox", "NativePasswordBoxDemo", "Brush.PasswordBox", "", "" ],
1919
[ "Expander", "ExpanderDemo", "Brush.Expander", "", "" ],

src/Avalonia/HandyControlDemo_Avalonia/HandyControlDemo_Avalonia.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
<AssemblyName>HandyControlDemo</AssemblyName>
1212
<RootNamespace>HandyControlDemo</RootNamespace>
1313
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
15+
<NoWarn>1701;1702;NETSDK1138</NoWarn>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
18+
<NoWarn>1701;1702;NETSDK1138</NoWarn>
19+
</PropertyGroup>
1420

1521
<ItemGroup>
1622
<None Remove="Data\DemoInfo.json" />
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:hc="https://handyorg.github.io/handycontrol"
6+
mc:Ignorable="d"
7+
d:DesignWidth="800"
8+
d:DesignHeight="450"
9+
x:Class="HandyControlDemo.UserControl.TextBoxDemo">
10+
<ScrollViewer>
11+
<hc:UniformSpacingPanel Spacing="32"
12+
Margin="32"
13+
ChildWrapping="Wrap">
14+
<StackPanel>
15+
<TextBox Text="This is the content" />
16+
<TextBox Text="This is the content"
17+
Margin="0,16,0,0"
18+
IsEnabled="False" />
19+
20+
<TextBox hc:TitleElement.Title="This is the title"
21+
Theme="{StaticResource TextBoxExtend}"
22+
Margin="0,32,0,0"
23+
Text="This is the content" />
24+
<TextBox hc:TitleElement.Title="This is the title"
25+
Theme="{StaticResource TextBoxExtend}"
26+
Margin="0,16,0,0"
27+
Text="This is the content"
28+
IsEnabled="False" />
29+
<TextBox Watermark="please enter email"
30+
hc:TitleElement.Title="This item must be filled in"
31+
Theme="{StaticResource TextBoxExtend}"
32+
hc:InfoElement.Necessary="True"
33+
Margin="0,16,0,0" />
34+
<TextBox Width="380"
35+
hc:TitleElement.TitleWidth="120"
36+
hc:TitleElement.TitlePlacement="Left"
37+
hc:TitleElement.Title="The title is on the left"
38+
Theme="{StaticResource TextBoxExtend}"
39+
Margin="0,32,0,0"
40+
Text="This is the content" />
41+
<TextBox Width="380"
42+
hc:TitleElement.TitleWidth="120"
43+
Watermark="Please enter content"
44+
hc:TitleElement.TitlePlacement="Left"
45+
hc:TitleElement.Title="The title is on the left"
46+
hc:InfoElement.Necessary="True"
47+
Theme="{StaticResource TextBoxExtend}"
48+
Margin="0,16,0,0" />
49+
</StackPanel>
50+
<StackPanel>
51+
<TextBox Text="This is the content"
52+
Theme="{StaticResource TextBox.Small}" />
53+
<TextBox Text="This is the content"
54+
Margin="0,16,0,0"
55+
IsEnabled="False"
56+
Theme="{StaticResource TextBox.Small}" />
57+
58+
<TextBox hc:TitleElement.Title="This is the title"
59+
Theme="{StaticResource TextBoxExtend.Small}"
60+
Margin="0,32,0,0"
61+
Text="This is the content" />
62+
<TextBox hc:TitleElement.Title="This is the title"
63+
Theme="{StaticResource TextBoxExtend.Small}"
64+
Margin="0,16,0,0"
65+
Text="This is the content"
66+
IsEnabled="False" />
67+
<TextBox Watermark="please enter email"
68+
hc:TitleElement.Title="This item must be filled in"
69+
Theme="{StaticResource TextBoxExtend.Small}"
70+
hc:InfoElement.Necessary="True"
71+
Margin="0,16,0,0" />
72+
<TextBox Width="380"
73+
hc:TitleElement.TitleWidth="120"
74+
hc:TitleElement.TitlePlacement="Left"
75+
hc:TitleElement.Title="The title is on the left"
76+
Theme="{StaticResource TextBoxExtend.Small}"
77+
Margin="0,32,0,0"
78+
Text="This is the content" />
79+
<TextBox Width="380"
80+
hc:TitleElement.TitleWidth="120"
81+
Watermark="Please enter content"
82+
hc:TitleElement.TitlePlacement="Left"
83+
hc:TitleElement.Title="The title is on the left"
84+
hc:InfoElement.Necessary="True"
85+
Theme="{StaticResource TextBoxExtend.Small}"
86+
Margin="0,16,0,0" />
87+
</StackPanel>
88+
</hc:UniformSpacingPanel>
89+
</ScrollViewer>
90+
</UserControl>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HandyControlDemo.UserControl;
2+
3+
public partial class TextBoxDemo : Avalonia.Controls.UserControl
4+
{
5+
public TextBoxDemo()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Avalonia;
2+
3+
namespace HandyControl.Controls;
4+
5+
public class InfoElement
6+
{
7+
public static readonly AttachedProperty<bool> NecessaryProperty =
8+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, bool>("Necessary", inherits: true);
9+
10+
public static void SetNecessary(AvaloniaObject element, bool value) => element.SetValue(NecessaryProperty, value);
11+
12+
public static bool GetNecessary(AvaloniaObject element) => element.GetValue(NecessaryProperty);
13+
14+
public static readonly AttachedProperty<object> SymbolProperty =
15+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, object>("Symbol", inherits: true);
16+
17+
public static void SetSymbol(AvaloniaObject element, object value) => element.SetValue(SymbolProperty, value);
18+
19+
public static object GetSymbol(AvaloniaObject element) => element.GetValue(SymbolProperty);
20+
21+
public static readonly AttachedProperty<double> ContentHeightProperty =
22+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, double>("ContentHeight", defaultValue: 28,
23+
inherits: true);
24+
25+
public static void SetContentHeight(AvaloniaObject element, double value) =>
26+
element.SetValue(ContentHeightProperty, value);
27+
28+
public static double GetContentHeight(AvaloniaObject element) => element.GetValue(ContentHeightProperty);
29+
30+
public static readonly AttachedProperty<double> MinContentHeightProperty =
31+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, double>("MinContentHeight", defaultValue: 28,
32+
inherits: true);
33+
34+
public static void SetMinContentHeight(AvaloniaObject element, double value) =>
35+
element.SetValue(MinContentHeightProperty, value);
36+
37+
public static double GetMinContentHeight(AvaloniaObject element) => element.GetValue(MinContentHeightProperty);
38+
39+
public static readonly AttachedProperty<double> MaxContentHeightProperty =
40+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, double>("MaxContentHeight",
41+
defaultValue: double.PositiveInfinity);
42+
43+
public static void SetMaxContentHeight(AvaloniaObject element, double value) =>
44+
element.SetValue(MaxContentHeightProperty, value);
45+
46+
public static double GetMaxContentHeight(AvaloniaObject element) => element.GetValue(MaxContentHeightProperty);
47+
48+
public static readonly AttachedProperty<string> RegexPatternProperty =
49+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, string>("RegexPattern");
50+
51+
public static void SetRegexPattern(AvaloniaObject element, string value) =>
52+
element.SetValue(RegexPatternProperty, value);
53+
54+
public static string GetRegexPattern(AvaloniaObject element) => element.GetValue(RegexPatternProperty);
55+
56+
public static readonly AttachedProperty<bool> ShowClearButtonProperty =
57+
AvaloniaProperty.RegisterAttached<InfoElement, AvaloniaObject, bool>("ShowClearButton");
58+
59+
public static void SetShowClearButton(AvaloniaObject element, bool value) =>
60+
element.SetValue(ShowClearButtonProperty, value);
61+
62+
public static bool GetShowClearButton(AvaloniaObject element) => element.GetValue(ShowClearButtonProperty);
63+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
4+
namespace HandyControl.Controls;
5+
6+
public class TextBlockAttach
7+
{
8+
public static readonly AttachedProperty<bool> AutoTooltipProperty =
9+
AvaloniaProperty.RegisterAttached<TextBlockAttach, AvaloniaObject, bool>("AutoTooltip", defaultValue: false);
10+
11+
public static void SetAutoTooltip(AvaloniaObject element, bool value) =>
12+
element.SetValue(AutoTooltipProperty, value);
13+
14+
public static bool GetAutoTooltip(AvaloniaObject element) => element.GetValue(AutoTooltipProperty);
15+
16+
static TextBlockAttach()
17+
{
18+
AutoTooltipProperty.Changed.AddClassHandler<AvaloniaObject>(OnAutoTooltipChanged);
19+
}
20+
21+
private static void OnAutoTooltipChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
22+
{
23+
if (d is not TextBlock ctl)
24+
{
25+
return;
26+
}
27+
28+
if (e.GetNewValue<bool>())
29+
{
30+
UpdateTooltip(ctl);
31+
ctl.SizeChanged += TextBlock_SizeChanged;
32+
}
33+
else
34+
{
35+
ctl.SizeChanged -= TextBlock_SizeChanged;
36+
}
37+
}
38+
39+
private static void TextBlock_SizeChanged(object? sender, SizeChangedEventArgs e)
40+
{
41+
if (sender is TextBlock textBlock)
42+
{
43+
UpdateTooltip(textBlock);
44+
}
45+
}
46+
47+
private static void UpdateTooltip(TextBlock textBlock)
48+
{
49+
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
50+
double width = textBlock.DesiredSize.Width - textBlock.Margin.Left - textBlock.Margin.Right;
51+
ToolTip.SetTip(textBlock, textBlock.Bounds.Width > width ? textBlock.Text : null);
52+
}
53+
}

src/Avalonia/HandyControl_Avalonia/Controls/Attach/TitleElement.cs

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Layout;
24
using Avalonia.Media;
5+
using HandyControl.Data;
36

47
namespace HandyControl.Controls;
58

69
public class TitleElement
710
{
8-
public static readonly AttachedProperty<IBrush?> BorderBrushProperty =
9-
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, IBrush?>("BorderBrush", inherits: true);
11+
public static readonly AttachedProperty<string> TitleProperty =
12+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, string>("Title");
1013

11-
public static void SetBorderBrush(AvaloniaObject element, IBrush? value) =>
12-
element.SetValue(BorderBrushProperty, value);
14+
public static void SetTitle(AvaloniaObject element, string value) => element.SetValue(TitleProperty, value);
1315

14-
public static IBrush? GetBorderBrush(AvaloniaObject element) => element.GetValue(BorderBrushProperty);
16+
public static string GetTitle(AvaloniaObject element) => element.GetValue(TitleProperty);
1517

1618
public static readonly AttachedProperty<IBrush?> BackgroundProperty =
1719
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, IBrush?>("Background", inherits: true);
@@ -28,4 +30,81 @@ public static void SetForeground(AvaloniaObject element, IBrush? value) =>
2830
element.SetValue(ForegroundProperty, value);
2931

3032
public static IBrush? GetForeground(AvaloniaObject element) => element.GetValue(ForegroundProperty);
33+
34+
public static readonly AttachedProperty<IBrush?> BorderBrushProperty =
35+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, IBrush?>("BorderBrush", inherits: true);
36+
37+
public static void SetBorderBrush(AvaloniaObject element, IBrush? value) =>
38+
element.SetValue(BorderBrushProperty, value);
39+
40+
public static IBrush? GetBorderBrush(AvaloniaObject element) => element.GetValue(BorderBrushProperty);
41+
42+
public static readonly AttachedProperty<TitlePlacementType> TitlePlacementProperty =
43+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, TitlePlacementType>("TitlePlacement",
44+
defaultValue: TitlePlacementType.Top, inherits: true);
45+
46+
public static void SetTitlePlacement(AvaloniaObject element, TitlePlacementType value) =>
47+
element.SetValue(TitlePlacementProperty, value);
48+
49+
public static TitlePlacementType GetTitlePlacement(AvaloniaObject element) =>
50+
element.GetValue(TitlePlacementProperty);
51+
52+
public static readonly AttachedProperty<GridLength> TitleWidthProperty =
53+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, GridLength>("TitleWidth",
54+
defaultValue: GridLength.Auto, inherits: true);
55+
56+
public static void SetTitleWidth(AvaloniaObject element, GridLength value) =>
57+
element.SetValue(TitleWidthProperty, value);
58+
59+
public static GridLength GetTitleWidth(AvaloniaObject element) => element.GetValue(TitleWidthProperty);
60+
61+
public static readonly AttachedProperty<HorizontalAlignment> HorizontalAlignmentProperty =
62+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, HorizontalAlignment>("HorizontalAlignment",
63+
inherits: true);
64+
65+
public static void SetHorizontalAlignment(AvaloniaObject element, HorizontalAlignment value) =>
66+
element.SetValue(HorizontalAlignmentProperty, value);
67+
68+
public static HorizontalAlignment GetHorizontalAlignment(AvaloniaObject element) =>
69+
element.GetValue(HorizontalAlignmentProperty);
70+
71+
public static readonly AttachedProperty<VerticalAlignment> VerticalAlignmentProperty =
72+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, VerticalAlignment>("VerticalAlignment",
73+
inherits: true);
74+
75+
public static void SetVerticalAlignment(AvaloniaObject element, VerticalAlignment value) =>
76+
element.SetValue(VerticalAlignmentProperty, value);
77+
78+
public static VerticalAlignment GetVerticalAlignment(AvaloniaObject element) =>
79+
element.GetValue(VerticalAlignmentProperty);
80+
81+
public static readonly AttachedProperty<Thickness> MarginOnTheLeftProperty =
82+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, Thickness>("MarginOnTheLeft", inherits: true);
83+
84+
public static void SetMarginOnTheLeft(AvaloniaObject element, Thickness value) =>
85+
element.SetValue(MarginOnTheLeftProperty, value);
86+
87+
public static Thickness GetMarginOnTheLeft(AvaloniaObject element) => element.GetValue(MarginOnTheLeftProperty);
88+
89+
public static readonly AttachedProperty<Thickness> MarginOnTheTopProperty =
90+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, Thickness>("MarginOnTheTop", inherits: true);
91+
92+
public static void SetMarginOnTheTop(AvaloniaObject element, Thickness value) =>
93+
element.SetValue(MarginOnTheTopProperty, value);
94+
95+
public static Thickness GetMarginOnTheTop(AvaloniaObject element) => element.GetValue(MarginOnTheTopProperty);
96+
97+
public static readonly AttachedProperty<double> MinHeightProperty =
98+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, double>("MinHeight");
99+
100+
public static void SetMinHeight(AvaloniaObject element, double value) => element.SetValue(MinHeightProperty, value);
101+
102+
public static double GetMinHeight(AvaloniaObject element) => element.GetValue(MinHeightProperty);
103+
104+
public static readonly AttachedProperty<double> MinWidthProperty =
105+
AvaloniaProperty.RegisterAttached<TitleElement, AvaloniaObject, double>("MinWidth");
106+
107+
public static void SetMinWidth(AvaloniaObject element, double value) => element.SetValue(MinWidthProperty, value);
108+
109+
public static double GetMinWidth(AvaloniaObject element) => element.GetValue(MinWidthProperty);
31110
}

0 commit comments

Comments
 (0)