feat: prototype.
This commit is contained in:
@@ -47,5 +47,6 @@
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<TextBox u:NumPad.Attach="True" Width="100" Watermark="Invoke NumPad"></TextBox>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
14
src/Ursa.Themes.Semi/Controls/NumPad.axaml
Normal file
14
src/Ursa.Themes.Semi/Controls/NumPad.axaml
Normal file
@@ -0,0 +1,14 @@
|
||||
<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:NumPad}" TargetType="{x:Type u:NumPad}">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:NumPad">
|
||||
<Border Padding="48">
|
||||
<Button Focusable="False" Name="{x:Static u:NumPad.PART_Seven}" Content="7" Width="32"></Button>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
@@ -22,6 +22,7 @@
|
||||
<ResourceInclude Source="MessageBox.axaml" />
|
||||
<ResourceInclude Source="NavMenu.axaml" />
|
||||
<ResourceInclude Source="NumericUpDown.axaml" />
|
||||
<ResourceInclude Source="NumPad.axaml" />
|
||||
<ResourceInclude Source="NumberDisplayer.axaml" />
|
||||
<ResourceInclude Source="Pagination.axaml" />
|
||||
<ResourceInclude Source="RangeSlider.axaml" />
|
||||
|
||||
78
src/Ursa/Controls/NumPad/NumPad.cs
Normal file
78
src/Ursa/Controls/NumPad/NumPad.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart(NumPad.PART_Seven, typeof(Button))]
|
||||
public class NumPad: TemplatedControl
|
||||
{
|
||||
public const string PART_Seven = "PART_Seven";
|
||||
private Button? _sevenButton;
|
||||
public static readonly StyledProperty<InputElement?> TargetProperty = AvaloniaProperty.Register<NumPad, InputElement?>(
|
||||
nameof(Target));
|
||||
|
||||
public InputElement? Target
|
||||
{
|
||||
get => GetValue(TargetProperty);
|
||||
set => SetValue(TargetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly AttachedProperty<bool> AttachProperty =
|
||||
AvaloniaProperty.RegisterAttached<NumPad, InputElement, bool>("Attach");
|
||||
|
||||
public static void SetAttach(InputElement obj, bool value) => obj.SetValue(AttachProperty, value);
|
||||
public static bool GetAttach(InputElement obj) => obj.GetValue(AttachProperty);
|
||||
|
||||
static NumPad()
|
||||
{
|
||||
TargetProperty.Changed.AddClassHandler<NumPad, InputElement?>((n, args) => n.OnTargetChanged(args));
|
||||
AttachProperty.Changed.AddClassHandler<InputElement, bool>((input, args)=> OnAttachNumPad(input, args));
|
||||
}
|
||||
|
||||
private static void OnAttachNumPad(InputElement input, AvaloniaPropertyChangedEventArgs<bool> args)
|
||||
{
|
||||
if (args.NewValue.Value)
|
||||
{
|
||||
GotFocusEvent.AddHandler(OnTargetGotFocus, input);
|
||||
}
|
||||
else
|
||||
{
|
||||
GotFocusEvent.RemoveHandler(OnTargetGotFocus, input);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTargetChanged(AvaloniaPropertyChangedEventArgs<InputElement?> args)
|
||||
{
|
||||
//GotFocusEvent.RemoveHandler(OnTargetGotFocus, args.OldValue.Value);
|
||||
//GotFocusEvent.AddHandler(OnTargetGotFocus, args.NewValue.Value);
|
||||
}
|
||||
|
||||
private static void OnTargetGotFocus(object sender, GotFocusEventArgs e)
|
||||
{
|
||||
var numPad = new NumPad() { Target = sender as InputElement };
|
||||
OverlayDialog.ShowCustom(numPad, new object());
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
Button.ClickEvent.RemoveHandler(OnSevenButtonClick, _sevenButton);
|
||||
_sevenButton = e.NameScope.Find<Button>(PART_Seven);
|
||||
Button.ClickEvent.AddHandler(OnSevenButtonClick, _sevenButton);
|
||||
}
|
||||
|
||||
private void OnSevenButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Target?.RaiseEvent(new TextInputEventArgs()
|
||||
{
|
||||
Source = this,
|
||||
RoutedEvent = TextInputEvent,
|
||||
Text = "7",
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user