Skip to content

Commit d192cdb

Browse files
committed
feat: add avalonia basic NumericUpDown style.
1 parent 35d706d commit d192cdb

File tree

10 files changed

+344
-71
lines changed

10 files changed

+344
-71
lines changed

src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
[ "ScrollViewer", "NativeScrollViewerDemo", "Brush.ScrollBox", "", "" ],
1414
[ "Slider", "SliderDemo", "Brush.Slider", "", "" ],
1515
[ "TextBlock", "TextBlockDemo", "Brush.TextBlock", "", "" ],
16+
[ "NumericUpDown", "NumericUpDownDemo", "Brush.NumericListBox", "", "" ],
1617
[ "TextBox", "TextBoxDemo", "Brush.TextBox", "", "" ],
1718
[ "ComboBox", "NativeComboBoxDemo", "Brush.ComboBox", "", "" ],
1819
[ "Expander", "ExpanderDemo", "Brush.Expander", "", "" ],
@@ -49,13 +50,9 @@
4950
[ "ButtonGroup", "ButtonGroupDemo", "Brush.ButtonGroup", "", "Button" ],
5051
[ "ProgressButton", "ProgressButtonDemo", "Brush.ProgressBarStatusBar8", "", "Button" ],
5152
[ "Poptip", "PoptipDemo", "Brush.ToolTip", "", "DataDisplay" ],
52-
[ "NumericUpDown", "NumericUpDownDemo", "Brush.NumericListBox", "", "DataEntry" ],
53-
[ "TextBox", "TextBoxDemo", "Brush.TextBox", "", "DataEntry" ],
54-
[ "ComboBox", "ComboBoxDemo", "Brush.ComboBox", "", "DataEntry" ],
5553
[ "CheckComboBox", "CheckComboBoxDemo", "Brush.CheckBoxList", "", "DataEntry" ],
5654
[ "AutoCompleteTextBox", "AutoCompleteTextBoxDemo", "Brush.AutoComplete", "1", "DataEntry" ],
5755
[ "PinBox", "PinBoxDemo", "Brush.Ellipsis", "", "DataEntry" ],
58-
[ "DatePicker", "DatePickerDemo", "Brush.DateTimePicker", "", "DataEntry" ],
5956
[ "Clock", "ClockDemo", "Brush.Time", "", "DataEntry" ],
6057
[ "TimePicker", "TimePickerDemo", "Brush.TimePicker", "", "DataEntry" ],
6158
[ "CalendarWithClock", "CalendarWithClockDemo", "Brush.Calendar", "", "DataEntry" ],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.NumericUpDownDemo"
6+
DataContext="{Binding InputElementDemo, Source={x:Static vm:ViewModelLocator.Instance}}">
7+
<ScrollViewer>
8+
<hc:UniformSpacingPanel Spacing="32"
9+
Margin="32"
10+
ChildWrapping="Wrap">
11+
<hc:UniformSpacingPanel Spacing="16"
12+
Orientation="Vertical">
13+
<NumericUpDown Value="0"
14+
Width="380"
15+
Maximum="100" />
16+
<NumericUpDown Value="0"
17+
IsEnabled="False" />
18+
<NumericUpDown Value="0"
19+
IsReadOnly="True" />
20+
</hc:UniformSpacingPanel>
21+
</hc:UniformSpacingPanel>
22+
</ScrollViewer>
23+
</UserControl>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HandyControlDemo.UserControl;
2+
3+
public partial class NumericUpDownDemo : Avalonia.Controls.UserControl
4+
{
5+
public NumericUpDownDemo()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:hc="clr-namespace:HandyControl.Controls"
4+
xmlns:system="clr-namespace:System;assembly=System.Runtime">
5+
<ControlTheme x:Key="{x:Type ButtonSpinner}"
6+
TargetType="ButtonSpinner">
7+
<Setter Property="hc:BorderElement.CornerRadius"
8+
Value="{StaticResource DefaultCornerRadius}" />
9+
<Setter Property="CornerRadius"
10+
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
11+
<Setter Property="MinHeight"
12+
Value="{StaticResource DefaultControlHeight}" />
13+
<Setter Property="Padding"
14+
Value="{StaticResource DefaultInputPadding}" />
15+
<Setter Property="VerticalContentAlignment"
16+
Value="Center" />
17+
<Setter Property="HorizontalContentAlignment"
18+
Value="Left" />
19+
<Setter Property="Background"
20+
Value="{DynamicResource RegionBrush}" />
21+
<Setter Property="BorderBrush"
22+
Value="{DynamicResource BorderBrush}" />
23+
<Setter Property="Foreground"
24+
Value="{DynamicResource PrimaryTextBrush}" />
25+
<Setter Property="BorderThickness"
26+
Value="1" />
27+
<Setter Property="Template">
28+
<ControlTemplate>
29+
<DataValidationErrors>
30+
<Panel>
31+
<Border Name="border"
32+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
33+
VerticalAlignment="{TemplateBinding VerticalAlignment}"
34+
Background="{TemplateBinding Background}"
35+
BorderBrush="{TemplateBinding BorderBrush}"
36+
BorderThickness="{TemplateBinding BorderThickness}"
37+
CornerRadius="{TemplateBinding CornerRadius}" />
38+
<DockPanel>
39+
<UniformGrid Name="PART_SpinnerPanel"
40+
TabIndex="2"
41+
DockPanel.Dock="Right"
42+
IsVisible="{TemplateBinding ShowButtonSpinner}"
43+
Rows="2">
44+
<RepeatButton Name="PART_IncreaseButton"
45+
Height="{x:Static system:Double.NaN}"
46+
Width="{x:Static system:Double.NaN}"
47+
Foreground="{TemplateBinding BorderBrush}"
48+
IsTabStop="{TemplateBinding IsTabStop}"
49+
Theme="{StaticResource RepeatButtonIcon}"
50+
VerticalContentAlignment="Bottom"
51+
VerticalAlignment="Stretch"
52+
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='0,0,1,0'}"
53+
hc:IconElement.Geometry="{StaticResource UpGeometry}"
54+
hc:IconElement.Height="6"
55+
hc:IconElement.Width="{x:Static system:Double.NaN}" />
56+
<RepeatButton Name="PART_DecreaseButton"
57+
Height="{x:Static system:Double.NaN}"
58+
Width="{x:Static system:Double.NaN}"
59+
Foreground="{TemplateBinding BorderBrush}"
60+
IsTabStop="{TemplateBinding IsTabStop}"
61+
Theme="{StaticResource RepeatButtonIcon}"
62+
VerticalContentAlignment="Top"
63+
VerticalAlignment="Stretch"
64+
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='0,0,1,0'}"
65+
hc:IconElement.Geometry="{StaticResource DownGeometry}"
66+
hc:IconElement.Height="6"
67+
hc:IconElement.Width="{x:Static system:Double.NaN}" />
68+
</UniformGrid>
69+
<ContentPresenter Name="PART_ContentPresenter"
70+
TabIndex="1"
71+
Padding="{TemplateBinding Padding}"
72+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
73+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
74+
Content="{TemplateBinding Content}"
75+
ContentTemplate="{TemplateBinding ContentTemplate}" />
76+
</DockPanel>
77+
</Panel>
78+
</DataValidationErrors>
79+
</ControlTemplate>
80+
</Setter>
81+
82+
<Style Selector="^:left">
83+
<Setter Property="HorizontalContentAlignment"
84+
Value="Right" />
85+
<Setter Property="Template">
86+
<ControlTemplate>
87+
<DataValidationErrors>
88+
<Panel>
89+
<Border Name="border"
90+
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
91+
VerticalAlignment="{TemplateBinding VerticalAlignment}"
92+
Background="{TemplateBinding Background}"
93+
BorderBrush="{TemplateBinding BorderBrush}"
94+
BorderThickness="{TemplateBinding BorderThickness}"
95+
CornerRadius="{TemplateBinding CornerRadius}" />
96+
<DockPanel>
97+
<UniformGrid Name="PART_SpinnerPanel"
98+
TabIndex="2"
99+
DockPanel.Dock="Left"
100+
IsVisible="{TemplateBinding ShowButtonSpinner}"
101+
Rows="2">
102+
<RepeatButton Name="PART_IncreaseButton"
103+
Height="{x:Static system:Double.NaN}"
104+
Width="{x:Static system:Double.NaN}"
105+
Foreground="{TemplateBinding BorderBrush}"
106+
IsTabStop="{TemplateBinding IsTabStop}"
107+
Theme="{StaticResource RepeatButtonIcon}"
108+
VerticalContentAlignment="Bottom"
109+
VerticalAlignment="Stretch"
110+
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='1,0,0,0'}"
111+
hc:IconElement.Geometry="{StaticResource UpGeometry}"
112+
hc:IconElement.Height="6"
113+
hc:IconElement.Width="{x:Static system:Double.NaN}" />
114+
<RepeatButton Name="PART_DecreaseButton"
115+
Height="{x:Static system:Double.NaN}"
116+
Width="{x:Static system:Double.NaN}"
117+
Foreground="{TemplateBinding BorderBrush}"
118+
IsTabStop="{TemplateBinding IsTabStop}"
119+
Theme="{StaticResource RepeatButtonIcon}"
120+
VerticalContentAlignment="Top"
121+
VerticalAlignment="Stretch"
122+
Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessSplitConverter}, ConverterParameter='1,0,0,0'}"
123+
hc:IconElement.Geometry="{StaticResource DownGeometry}"
124+
hc:IconElement.Height="6"
125+
hc:IconElement.Width="{x:Static system:Double.NaN}" />
126+
</UniformGrid>
127+
<ContentPresenter Name="PART_ContentPresenter"
128+
TabIndex="1"
129+
Padding="{TemplateBinding Padding}"
130+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
131+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
132+
Content="{TemplateBinding Content}"
133+
ContentTemplate="{TemplateBinding ContentTemplate}" />
134+
</DockPanel>
135+
</Panel>
136+
</DataValidationErrors>
137+
</ControlTemplate>
138+
</Setter>
139+
</Style>
140+
</ControlTheme>
141+
</ResourceDictionary>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:hc="clr-namespace:HandyControl.Controls"
4+
xmlns:system="clr-namespace:System;assembly=System.Runtime">
5+
6+
<ControlTheme x:Key="NumericUpDownBaseStyle"
7+
TargetType="NumericUpDown">
8+
<Setter Property="hc:TitleElement.MarginOnTheLeft"
9+
Value="0,7,6,0" />
10+
<Setter Property="hc:TitleElement.MarginOnTheTop"
11+
Value="8,0,0,5" />
12+
<Setter Property="hc:TitleElement.HorizontalAlignment"
13+
Value="Left" />
14+
<Setter Property="hc:BorderElement.CornerRadius"
15+
Value="{StaticResource DefaultCornerRadius}" />
16+
<Setter Property="CornerRadius"
17+
Value="{Binding $self.(hc:BorderElement.CornerRadius)}" />
18+
<Setter Property="MinHeight"
19+
Value="{StaticResource DefaultControlHeight}" />
20+
<Setter Property="Padding"
21+
Value="{StaticResource DefaultInputPadding}" />
22+
<Setter Property="VerticalContentAlignment"
23+
Value="Center" />
24+
<Setter Property="HorizontalContentAlignment"
25+
Value="Left" />
26+
<Setter Property="Background"
27+
Value="{DynamicResource RegionBrush}" />
28+
<Setter Property="BorderBrush"
29+
Value="{DynamicResource BorderBrush}" />
30+
<Setter Property="Foreground"
31+
Value="{DynamicResource PrimaryTextBrush}" />
32+
<Setter Property="BorderThickness"
33+
Value="1" />
34+
<Setter Property="Template">
35+
<ControlTemplate>
36+
<DataValidationErrors>
37+
<ButtonSpinner Name="PART_Spinner"
38+
HorizontalContentAlignment="Stretch"
39+
VerticalContentAlignment="Stretch"
40+
IsTabStop="False"
41+
Padding="{TemplateBinding Padding}"
42+
MinWidth="0"
43+
AllowSpin="{TemplateBinding AllowSpin}"
44+
Background="{TemplateBinding Background}"
45+
BorderBrush="{TemplateBinding BorderBrush}"
46+
BorderThickness="{TemplateBinding BorderThickness}"
47+
ButtonSpinnerLocation="{TemplateBinding ButtonSpinnerLocation}"
48+
CornerRadius="{TemplateBinding CornerRadius}"
49+
ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}">
50+
<TextBox Name="PART_TextBox"
51+
Background="Transparent"
52+
BorderBrush="Transparent"
53+
BorderThickness="0"
54+
Padding="0"
55+
MinWidth="0"
56+
Foreground="{TemplateBinding Foreground}"
57+
Watermark="{TemplateBinding Watermark}"
58+
IsReadOnly="{TemplateBinding IsReadOnly}"
59+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
60+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
61+
Text="{TemplateBinding Text}"
62+
TextAlignment="{TemplateBinding TextAlignment}"
63+
AcceptsReturn="False"
64+
TextWrapping="NoWrap" />
65+
</ButtonSpinner>
66+
</DataValidationErrors>
67+
</ControlTemplate>
68+
</Setter>
69+
70+
<Style Selector="^:disabled">
71+
<Setter Property="Opacity"
72+
Value="0.4" />
73+
</Style>
74+
75+
<Style Selector="^:pointerover /template/ ButtonSpinner#PART_Spinner">
76+
<Setter Property="BorderBrush"
77+
Value="{DynamicResource SecondaryBorderBrush}" />
78+
</Style>
79+
80+
<Style Selector="^:focus-within">
81+
<Style Selector="^:pointerover /template/ ButtonSpinner#PART_Spinner">
82+
<Setter Property="BorderBrush"
83+
Value="{DynamicResource PrimaryBrush}" />
84+
</Style>
85+
<Setter Property="BorderBrush"
86+
Value="{DynamicResource PrimaryBrush}" />
87+
</Style>
88+
89+
<Style Selector="^:error /template/ ButtonSpinner#PART_Spinner">
90+
<Setter Property="BorderBrush"
91+
Value="{DynamicResource DangerBrush}" />
92+
</Style>
93+
</ControlTheme>
94+
95+
<ControlTheme x:Key="{x:Type NumericUpDown}"
96+
BasedOn="{StaticResource NumericUpDownBaseStyle}"
97+
TargetType="NumericUpDown" />
98+
99+
</ResourceDictionary>

0 commit comments

Comments
 (0)