feat: initialize.
This commit is contained in:
@@ -14,6 +14,7 @@ public static class MenuKeys
|
||||
public const string MenuKeyKeyGestureInput = "KeyGestureInput";
|
||||
public const string MenuKeyLoading = "Loading";
|
||||
public const string MenuKeyNavigation = "Navigation";
|
||||
public const string MenuKeyNumericUpDown = "NumericUpDown";
|
||||
public const string MenuKeyPagination = "Pagination";
|
||||
public const string MenuKeyTagInput = "TagInput";
|
||||
public const string MenuKeyTimeline = "Timeline";
|
||||
|
||||
14
demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml
Normal file
14
demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml
Normal file
@@ -0,0 +1,14 @@
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Pages.NumericUpDownDemo"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<u:IntUpDown />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
15
demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml.cs
Normal file
15
demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Ursa.Demo.ViewModels;
|
||||
|
||||
namespace Ursa.Demo.Pages;
|
||||
|
||||
public partial class NumericUpDownDemo : UserControl
|
||||
{
|
||||
public NumericUpDownDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new NumericUpDownDemoViewModel();
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class MainViewViewModel : ViewModelBase
|
||||
MenuKeys.MenuKeyKeyGestureInput => new KeyGestureInputDemoViewModel(),
|
||||
MenuKeys.MenuKeyLoading => new LoadingDemoViewModel(),
|
||||
MenuKeys.MenuKeyNavigation => new NavigationMenuDemoViewModel(),
|
||||
MenuKeys.MenuKeyNumericUpDown => new NumericUpDownDemoViewModel(),
|
||||
MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(),
|
||||
MenuKeys.MenuKeyTagInput => new TagInputDemoViewModel(),
|
||||
MenuKeys.MenuKeyTimeline => new TimelineDemoViewModel(),
|
||||
|
||||
@@ -23,6 +23,7 @@ public class MenuViewModel: ViewModelBase
|
||||
new() { MenuHeader = "KeyGestureInput", Key = MenuKeys.MenuKeyKeyGestureInput },
|
||||
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading },
|
||||
new() { MenuHeader = "Navigation", Key = MenuKeys.MenuKeyNavigation },
|
||||
new() { MenuHeader = "NumericUpDown", Key = MenuKeys.MenuKeyNumericUpDown },
|
||||
new() { MenuHeader = "Pagination", Key = MenuKeys.MenuKeyPagination },
|
||||
new() { MenuHeader = "TagInput", Key = MenuKeys.MenuKeyTagInput },
|
||||
new() { MenuHeader = "Timeline", Key = MenuKeys.MenuKeyTimeline },
|
||||
|
||||
8
demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs
Normal file
8
demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public class NumericUpDownDemoViewModel: ObservableObject
|
||||
{
|
||||
|
||||
}
|
||||
12
src/Ursa.Themes.Semi/Controls/NumericUpDown.axaml
Normal file
12
src/Ursa.Themes.Semi/Controls/NumericUpDown.axaml
Normal file
@@ -0,0 +1,12 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<!-- Add Resources Here -->
|
||||
<ControlTheme x:Key="{x:Type u:NumericUpDown}" TargetType="{x:Type u:NumericUpDown}">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Rectangle Fill="Red" Width="100" Height="100"></Rectangle>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
@@ -12,6 +12,7 @@
|
||||
<ResourceInclude Source="KeyGestureInput.axaml" />
|
||||
<ResourceInclude Source="Loading.axaml" />
|
||||
<ResourceInclude Source="Navigation.axaml" />
|
||||
<ResourceInclude Source="NumericUpDown.axaml" />
|
||||
<ResourceInclude Source="Pagination.axaml" />
|
||||
<ResourceInclude Source="TagInput.axaml" />
|
||||
<ResourceInclude Source="Timeline.axaml" />
|
||||
|
||||
22
src/Ursa/Controls/NumericUpDown/IntUpDown.cs
Normal file
22
src/Ursa/Controls/NumericUpDown/IntUpDown.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class IntUpDown: NumericUpDownBase<int>
|
||||
{
|
||||
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||
|
||||
static IntUpDown()
|
||||
{
|
||||
MaximumProperty.OverrideDefaultValue<IntUpDown>(100);
|
||||
}
|
||||
|
||||
protected override void Increase()
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
Value += Maximum;
|
||||
}
|
||||
|
||||
protected override void Decrease()
|
||||
{
|
||||
Value -= Maximum;
|
||||
}
|
||||
}
|
||||
133
src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs
Normal file
133
src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart(PART_Spinner, typeof(ButtonSpinner))]
|
||||
[TemplatePart(PART_TextBox, typeof(TextBox))]
|
||||
public abstract class NumericUpDown : TemplatedControl
|
||||
{
|
||||
public const string PART_Spinner = "PART_Spinner";
|
||||
public const string PART_TextBox = "PART_TextBox";
|
||||
|
||||
private Avalonia.Controls.NumericUpDown? _numericUpDown;
|
||||
private ButtonSpinner? _spinner;
|
||||
private TextBox? _textBox;
|
||||
|
||||
public static readonly StyledProperty<bool> TextEditableProperty = AvaloniaProperty.Register<NumericUpDown, bool>(
|
||||
nameof(TextEditable), defaultValue: true);
|
||||
|
||||
public bool TextEditable
|
||||
{
|
||||
get => GetValue(TextEditableProperty);
|
||||
set => SetValue(TextEditableProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> IsReadOnlyProperty = AvaloniaProperty.Register<NumericUpDown, bool>(
|
||||
nameof(IsReadOnly));
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get => GetValue(IsReadOnlyProperty);
|
||||
set => SetValue(IsReadOnlyProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> InnerLeftContentProperty = AvaloniaProperty.Register<NumericUpDown, object?>(
|
||||
nameof(InnerLeftContent));
|
||||
|
||||
public object? InnerLeftContent
|
||||
{
|
||||
get => GetValue(InnerLeftContentProperty);
|
||||
set => SetValue(InnerLeftContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<string?> WatermarkProperty = AvaloniaProperty.Register<NumericUpDown, string?>(
|
||||
nameof(Watermark));
|
||||
|
||||
public string? Watermark
|
||||
{
|
||||
get => GetValue(WatermarkProperty);
|
||||
set => SetValue(WatermarkProperty, value);
|
||||
}
|
||||
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
if(_spinner is not null)
|
||||
{
|
||||
_spinner.Spin -= OnSpin;
|
||||
}
|
||||
if(_textBox is not null)
|
||||
{
|
||||
_textBox.TextChanged -= OnTextChange;
|
||||
}
|
||||
_spinner = e.NameScope.Find<ButtonSpinner>(PART_Spinner);
|
||||
_textBox = e.NameScope.Find<TextBox>(PART_TextBox);
|
||||
if (_spinner is not null)
|
||||
{
|
||||
_spinner.Spin += OnSpin;
|
||||
}
|
||||
|
||||
if (_textBox is not null)
|
||||
{
|
||||
_textBox.TextChanged += OnTextChange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnTextChange(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnSpin(object sender, SpinEventArgs e)
|
||||
{
|
||||
if (e.Direction == SpinDirection.Increase)
|
||||
{
|
||||
Increase();
|
||||
}
|
||||
else
|
||||
{
|
||||
Decrease();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void Increase();
|
||||
protected abstract void Decrease();
|
||||
}
|
||||
|
||||
public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComparable<T>
|
||||
{
|
||||
public static readonly StyledProperty<T> ValueProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
||||
nameof(Value));
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<T> MaximumProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
||||
nameof(Maximum));
|
||||
|
||||
public T Maximum
|
||||
{
|
||||
get => GetValue(MaximumProperty);
|
||||
set => SetValue(MaximumProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<T> MinimumProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
||||
nameof(Minimum));
|
||||
|
||||
public T Minimum
|
||||
{
|
||||
get => GetValue(MinimumProperty);
|
||||
set => SetValue(MinimumProperty, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user