Skip to content

Commit 94ee336

Browse files
committed
feat: add avalonia basic ComboBox style.
1 parent d4406c2 commit 94ee336

File tree

12 files changed

+593
-8
lines changed

12 files changed

+593
-8
lines changed

src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[ "TextBlock", "TextBlockDemo", "Brush.TextBlock", "", "" ],
1616
[ "NumericUpDown", "NumericUpDownDemo", "Brush.NumericListBox", "", "" ],
1717
[ "TextBox", "TextBoxDemo", "Brush.TextBox", "", "" ],
18-
[ "ComboBox", "NativeComboBoxDemo", "Brush.ComboBox", "", "" ],
18+
[ "ComboBox", "ComboBoxDemo", "Brush.ComboBox", "", "" ],
1919
[ "Expander", "ExpanderDemo", "Brush.Expander", "", "" ],
2020
[ "ProgressBar", "NativeProgressBarDemo", "Brush.ProgressBar", "", "" ],
2121
[ "Calendar", "CalendarDemo", "Brush.Calendar", "", "" ],
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:hc="https://handyorg.github.io/handycontrol"
4+
xmlns:vm="clr-namespace:HandyControlDemo.ViewModel"
5+
x:Class="HandyControlDemo.UserControl.ComboBoxDemo"
6+
DataContext="{Binding InputElementDemo, Source={x:Static vm:ViewModelLocator.Instance}}">
7+
<ScrollViewer>
8+
<hc:UniformSpacingPanel Spacing="32"
9+
Margin="32"
10+
ChildWrapping="Wrap">
11+
<StackPanel>
12+
<ComboBox ItemsSource="{Binding DataList}" />
13+
<ComboBox ItemsSource="{Binding DataList}"
14+
Margin="0,16,0,0"
15+
IsEnabled="False" />
16+
17+
<ComboBox hc:TitleElement.Title="This is the title"
18+
Theme="{StaticResource ComboBoxExtend}"
19+
Margin="0,32,0,0"
20+
ItemsSource="{Binding DataList}" />
21+
<ComboBox hc:TitleElement.Title="This is the title"
22+
hc:InfoElement.ShowClearButton="True"
23+
Theme="{StaticResource ComboBoxExtend}"
24+
Margin="0,32,0,0"
25+
ItemsSource="{Binding DataList}" />
26+
<ComboBox hc:TitleElement.Title="This is the title"
27+
Theme="{StaticResource ComboBoxExtend}"
28+
Margin="0,16,0,0"
29+
ItemsSource="{Binding DataList}"
30+
IsEnabled="False" />
31+
<ComboBox PlaceholderText="Please enter content"
32+
ItemsSource="{Binding DataList}"
33+
hc:TitleElement.Title="This item must be filled in"
34+
Theme="{StaticResource ComboBoxExtend}"
35+
hc:InfoElement.Necessary="True"
36+
Margin="0,16,0,0" />
37+
<ComboBox Width="380"
38+
hc:TitleElement.TitleWidth="120"
39+
hc:TitleElement.TitlePlacement="Left"
40+
hc:TitleElement.Title="The title is on the left"
41+
Theme="{StaticResource ComboBoxExtend}"
42+
Margin="0,32,0,0"
43+
ItemsSource="{Binding DataList}" />
44+
<ComboBox Width="380"
45+
ItemsSource="{Binding DataList}"
46+
hc:TitleElement.TitleWidth="120"
47+
PlaceholderText="Please enter content"
48+
hc:TitleElement.TitlePlacement="Left"
49+
hc:TitleElement.Title="The title is on the left"
50+
hc:InfoElement.Necessary="True"
51+
Theme="{StaticResource ComboBoxExtend}"
52+
Margin="0,16,0,0" />
53+
</StackPanel>
54+
<StackPanel>
55+
<ComboBox ItemsSource="{Binding DataList}"
56+
Theme="{StaticResource ComboBox.Small}" />
57+
<ComboBox ItemsSource="{Binding DataList}"
58+
Margin="0,16,0,0"
59+
IsEnabled="False"
60+
Theme="{StaticResource ComboBox.Small}" />
61+
62+
<ComboBox hc:TitleElement.Title="This is the title"
63+
Theme="{StaticResource ComboBoxExtend.Small}"
64+
Margin="0,32,0,0"
65+
ItemsSource="{Binding DataList}" />
66+
<ComboBox hc:TitleElement.Title="This is the title"
67+
hc:InfoElement.ShowClearButton="True"
68+
Theme="{StaticResource ComboBoxExtend.Small}"
69+
Margin="0,32,0,0"
70+
ItemsSource="{Binding DataList}" />
71+
<ComboBox hc:TitleElement.Title="This is the title"
72+
Theme="{StaticResource ComboBoxExtend.Small}"
73+
Margin="0,16,0,0"
74+
ItemsSource="{Binding DataList}"
75+
IsEnabled="False" />
76+
<ComboBox PlaceholderText="Please enter content"
77+
ItemsSource="{Binding DataList}"
78+
hc:TitleElement.Title="This item must be filled in"
79+
Theme="{StaticResource ComboBoxExtend.Small}"
80+
hc:InfoElement.Necessary="True"
81+
Margin="0,16,0,0" />
82+
<ComboBox Width="380"
83+
hc:TitleElement.TitleWidth="120"
84+
hc:TitleElement.TitlePlacement="Left"
85+
hc:TitleElement.Title="The title is on the left"
86+
Theme="{StaticResource ComboBoxExtend.Small}"
87+
Margin="0,32,0,0"
88+
ItemsSource="{Binding DataList}" />
89+
<ComboBox Width="380"
90+
ItemsSource="{Binding DataList}"
91+
hc:TitleElement.TitleWidth="120"
92+
PlaceholderText="Please enter content"
93+
hc:TitleElement.TitlePlacement="Left"
94+
hc:TitleElement.Title="The title is on the left"
95+
hc:InfoElement.Necessary="True"
96+
Theme="{StaticResource ComboBoxExtend.Small}"
97+
Margin="0,16,0,0" />
98+
</StackPanel>
99+
</hc:UniformSpacingPanel>
100+
</ScrollViewer>
101+
</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 ComboBoxDemo : Avalonia.Controls.UserControl
4+
{
5+
public ComboBoxDemo()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+

src/Avalonia/HandyControlDemo_Avalonia/ViewModel/Common/InputElementDemoViewModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
using System.Collections.Generic;
12
using System.ComponentModel.DataAnnotations;
3+
using System.Globalization;
24
using CommunityToolkit.Mvvm.ComponentModel;
5+
using HandyControlDemo.Properties.Langs;
6+
using HandyControlDemo.Tools.Converter;
37

48
namespace HandyControlDemo.ViewModel;
59

@@ -20,4 +24,23 @@ [Required] [ObservableProperty] [NotifyDataErrorInfo]
2024
[ObservableProperty] private double? _doubleValue1;
2125

2226
[ObservableProperty] private double? _doubleValue2;
27+
28+
[ObservableProperty] private IList<string>? _dataList;
29+
30+
public InputElementDemoViewModel()
31+
{
32+
DataList = GetComboBoxDemoDataList();
33+
}
34+
35+
private static List<string> GetComboBoxDemoDataList()
36+
{
37+
var converter = new StringRepeatConverter();
38+
var list = new List<string>();
39+
for (int i = 1; i <= 9; i++)
40+
{
41+
list.Add($"{converter.Convert(Lang.Text, null!, i, CultureInfo.CurrentCulture)}{i}");
42+
}
43+
44+
return list;
45+
}
2346
}

0 commit comments

Comments
 (0)