diff --git a/demo/Ursa.Demo/Pages/BannerDemo.axaml b/demo/Ursa.Demo/Pages/BannerDemo.axaml
index 5cdb150..d7a275e 100644
--- a/demo/Ursa.Demo/Pages/BannerDemo.axaml
+++ b/demo/Ursa.Demo/Pages/BannerDemo.axaml
@@ -47,10 +47,5 @@
-
-
-
-
-
diff --git a/demo/Ursa.Demo/Pages/NumPadDemo.axaml b/demo/Ursa.Demo/Pages/NumPadDemo.axaml
new file mode 100644
index 0000000..b593e7b
--- /dev/null
+++ b/demo/Ursa.Demo/Pages/NumPadDemo.axaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/demo/Ursa.Demo/Pages/NumPadDemo.axaml.cs b/demo/Ursa.Demo/Pages/NumPadDemo.axaml.cs
new file mode 100644
index 0000000..b82a6ae
--- /dev/null
+++ b/demo/Ursa.Demo/Pages/NumPadDemo.axaml.cs
@@ -0,0 +1,14 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Markup.Xaml;
+
+namespace Ursa.Demo.Pages;
+
+public partial class NumPadDemo : UserControl
+{
+ public NumPadDemo()
+ {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs b/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs
index 5a0cd77..514ee9a 100644
--- a/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs
@@ -46,6 +46,7 @@ public class MainViewViewModel : ViewModelBase
MenuKeys.MenuKeyNavMenu => new NavMenuDemoViewModel(),
MenuKeys.MenuKeyNumberDisplayer => new NumberDisplayerDemoViewModel(),
MenuKeys.MenuKeyNumericUpDown => new NumericUpDownDemoViewModel(),
+ MenuKeys.MenuKeyNumPad => new NumPadDemoViewModel(),
MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(),
MenuKeys.MenuKeyRangeSlider => new RangeSliderDemoViewModel(),
MenuKeys.MenuKeyScrollToButton => new ScrollToButtonDemoViewModel(),
diff --git a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs
index a48238e..888e74d 100644
--- a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs
@@ -33,6 +33,7 @@ public class MenuViewModel: ViewModelBase
new() { MenuHeader = "Nav Menu", Key = MenuKeys.MenuKeyNavMenu, Status = "New"},
// new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
+ new() { MenuHeader = "NumPad", Key = MenuKeys.MenuKeyNumPad, Status = "New" },
new() { MenuHeader = "Pagination", Key = MenuKeys.MenuKeyPagination },
new() { MenuHeader = "RangeSlider", Key = MenuKeys.MenuKeyRangeSlider },
new() { MenuHeader = "Scroll To", Key = MenuKeys.MenuKeyScrollToButton, Status = "New" },
@@ -71,6 +72,7 @@ public static class MenuKeys
public const string MenuKeyNavMenu = "NavMenu";
public const string MenuKeyNumberDisplayer = "NumberDisplayer";
public const string MenuKeyNumericUpDown = "NumericUpDown";
+ public const string MenuKeyNumPad = "NumPad";
public const string MenuKeyPagination = "Pagination";
public const string MenuKeyRangeSlider = "RangeSlider";
public const string MenuKeyScrollToButton = "ScrollToButton";
diff --git a/demo/Ursa.Demo/ViewModels/NumPadDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/NumPadDemoViewModel.cs
new file mode 100644
index 0000000..88fcfb1
--- /dev/null
+++ b/demo/Ursa.Demo/ViewModels/NumPadDemoViewModel.cs
@@ -0,0 +1,6 @@
+namespace Ursa.Demo.ViewModels;
+
+public class NumPadDemoViewModel
+{
+
+}
\ No newline at end of file
diff --git a/src/Ursa.Themes.Semi/Controls/NumPad.axaml b/src/Ursa.Themes.Semi/Controls/NumPad.axaml
index 5104b42..c5339e4 100644
--- a/src/Ursa.Themes.Semi/Controls/NumPad.axaml
+++ b/src/Ursa.Themes.Semi/Controls/NumPad.axaml
@@ -9,73 +9,85 @@
+
-
-
+
-
+
+
+
+
+
+
+
-
-
-
+
-
-
-
-
-
-
+ FunctionContent="Home"
+ FunctionKey="Home"
+ NumContent="7"
+ NumKey="NumPad7" />
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Ursa/Controls/NumPad/NumPad.cs b/src/Ursa/Controls/NumPad/NumPad.cs
index e1bcb7f..ae8d8da 100644
--- a/src/Ursa/Controls/NumPad/NumPad.cs
+++ b/src/Ursa/Controls/NumPad/NumPad.cs
@@ -10,7 +10,6 @@ namespace Ursa.Controls;
public class NumPad: TemplatedControl
{
- private Button? _sevenButton;
public static readonly StyledProperty TargetProperty = AvaloniaProperty.Register(
nameof(Target));
@@ -20,6 +19,15 @@ public class NumPad: TemplatedControl
set => SetValue(TargetProperty, value);
}
+ public static readonly StyledProperty NumModeProperty = AvaloniaProperty.Register(
+ nameof(NumMode), defaultValue: true);
+
+ public bool NumMode
+ {
+ get => GetValue(NumModeProperty);
+ set => SetValue(NumModeProperty, value);
+ }
+
public static readonly AttachedProperty AttachProperty =
AvaloniaProperty.RegisterAttached("Attach");
@@ -28,8 +36,7 @@ public class NumPad: TemplatedControl
static NumPad()
{
- TargetProperty.Changed.AddClassHandler((n, args) => n.OnTargetChanged(args));
- AttachProperty.Changed.AddClassHandler((input, args)=> OnAttachNumPad(input, args));
+ AttachProperty.Changed.AddClassHandler(OnAttachNumPad);
}
private static void OnAttachNumPad(InputElement input, AvaloniaPropertyChangedEventArgs args)
@@ -43,12 +50,6 @@ public class NumPad: TemplatedControl
GotFocusEvent.RemoveHandler(OnTargetGotFocus, input);
}
}
-
- private void OnTargetChanged(AvaloniaPropertyChangedEventArgs args)
- {
- //GotFocusEvent.RemoveHandler(OnTargetGotFocus, args.OldValue.Value);
- //GotFocusEvent.AddHandler(OnTargetGotFocus, args.NewValue.Value);
- }
private static void OnTargetGotFocus(object sender, GotFocusEventArgs e)
{
@@ -63,23 +64,54 @@ public class NumPad: TemplatedControl
OverlayDialog.Show(numPad, new object(), options: new OverlayDialogOptions() { Buttons = DialogButton.None });
}
- private void OnSevenButtonClick(object sender, RoutedEventArgs e)
+ private Dictionary _keyInputMapping = new()
{
- Target?.RaiseEvent(new TextInputEventArgs()
- {
- Source = this,
- RoutedEvent = TextInputEvent,
- Text = "7",
- });
- }
+ [Key.NumPad0] = "0",
+ [Key.NumPad1] = "1",
+ [Key.NumPad2] = "2",
+ [Key.NumPad3] = "3",
+ [Key.NumPad4] = "4",
+ [Key.NumPad5] = "5",
+ [Key.NumPad6] = "6",
+ [Key.NumPad7] = "7",
+ [Key.NumPad8] = "8",
+ [Key.NumPad9] = "9",
+ [Key.OemPlus] = "+",
+ [Key.OemMinus] = "-",
+ };
- public void InputNumber(object o)
+ public void ProcessClick(object o)
{
- Target?.RaiseEvent(new TextInputEventArgs()
+ if (o is NumPadButton b)
{
- Source = this,
- RoutedEvent = TextInputEvent,
- Text = o.ToString(),
- });
+ if (b is { NumMode: true, NumKey: not null })
+ {
+ Target?.RaiseEvent(new TextInputEventArgs()
+ {
+ Source = this,
+ RoutedEvent = TextInputEvent,
+ Text = _keyInputMapping.TryGetValue(b.NumKey.Value, out var text)? text:string.Empty,
+ });
+ }
+ else if (b is { NumMode: false, FunctionKey: null, NumKey: not null })
+ {
+ Target?.RaiseEvent(new TextInputEventArgs()
+ {
+ Source = this,
+ RoutedEvent = TextInputEvent,
+ Text = _keyInputMapping.TryGetValue(b.NumKey.Value, out var text)? text:string.Empty,
+ });
+ }
+ else
+ {
+ Target?.RaiseEvent(new KeyEventArgs()
+ {
+ Source = this,
+ RoutedEvent = KeyDownEvent,
+ Key = b.FunctionKey ?? Key.None,
+ });
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/src/Ursa/Controls/NumPad/NumPadButton.cs b/src/Ursa/Controls/NumPad/NumPadButton.cs
new file mode 100644
index 0000000..0aa368f
--- /dev/null
+++ b/src/Ursa/Controls/NumPad/NumPadButton.cs
@@ -0,0 +1,54 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+
+namespace Ursa.Controls;
+
+public class NumPadButton: RepeatButton
+{
+ public static readonly StyledProperty NumKeyProperty = AvaloniaProperty.Register(
+ nameof(NumKey));
+
+ public Key? NumKey
+ {
+ get => GetValue(NumKeyProperty);
+ set => SetValue(NumKeyProperty, value);
+ }
+
+ public static readonly StyledProperty FunctionKeyProperty = AvaloniaProperty.Register(
+ nameof(FunctionKey));
+
+ public Key? FunctionKey
+ {
+ get => GetValue(FunctionKeyProperty);
+ set => SetValue(FunctionKeyProperty, value);
+ }
+
+ public static readonly StyledProperty NumModeProperty = AvaloniaProperty.Register(
+ nameof(NumMode));
+
+ public bool NumMode
+ {
+ get => GetValue(NumModeProperty);
+ set => SetValue(NumModeProperty, value);
+ }
+
+ public static readonly StyledProperty