commit: temporarily use TextBox
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@@ -5,27 +6,37 @@ using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart(PART_FirstTextPresenter, typeof(TextPresenter))]
|
||||
[TemplatePart(PART_SecondTextPresenter, typeof(TextPresenter))]
|
||||
[TemplatePart(PART_ThirdTextPresenter, typeof(TextPresenter))]
|
||||
[TemplatePart(PART_FourthTextPresenter, typeof(TextPresenter))]
|
||||
[TemplatePart(PART_PortNumericInput, typeof(NumericUpDown))]
|
||||
[TemplatePart(PART_FirstTextBox, typeof(TextBox))]
|
||||
[TemplatePart(PART_SecondTextBox, typeof(TextBox))]
|
||||
[TemplatePart(PART_ThirdTextBox, typeof(TextBox))]
|
||||
[TemplatePart(PART_FourthTextBox, typeof(TextBox))]
|
||||
[TemplatePart(PART_PortTextBox, typeof(TextBox))]
|
||||
public class IPv4Box: TemplatedControl
|
||||
{
|
||||
public const string PART_FirstTextPresenter = "PART_FirstTextPresenter";
|
||||
public const string PART_SecondTextPresenter = "PART_SecondTextPresenter";
|
||||
public const string PART_ThirdTextPresenter = "PART_ThirdTextPresenter";
|
||||
public const string PART_FourthTextPresenter = "PART_FourthTextPresenter";
|
||||
public const string PART_PortNumericInput = "PART_PortNumericInput";
|
||||
private TextPresenter? _firstTextPresenter;
|
||||
private TextPresenter? _secondTextPresenter;
|
||||
private TextPresenter? _thirdTextPresenter;
|
||||
private TextPresenter? _fourthTextPresenter;
|
||||
private NumericUpDown? _portNumericInput;
|
||||
public const string PART_FirstTextBox = "PART_FirstTextPresenter";
|
||||
public const string PART_SecondTextBox = "PART_SecondTextPresenter";
|
||||
public const string PART_ThirdTextBox = "PART_ThirdTextPresenter";
|
||||
public const string PART_FourthTextBox = "PART_FourthTextPresenter";
|
||||
public const string PART_PortTextBox = "PART_PortNumericInput";
|
||||
private TextBox? _firstText;
|
||||
private TextBox? _secondText;
|
||||
private TextBox? _thirdText;
|
||||
private TextBox? _fourthText;
|
||||
private TextBox? _portText;
|
||||
|
||||
public static readonly StyledProperty<bool> ShowPortProperty = AvaloniaProperty.Register<IPv4Box, bool>(
|
||||
nameof(ShowPort));
|
||||
|
||||
public bool ShowPort
|
||||
{
|
||||
get => GetValue(ShowPortProperty);
|
||||
set => SetValue(ShowPortProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IPAddress> IPAddressProperty = AvaloniaProperty.Register<IPv4Box, IPAddress>(
|
||||
nameof(IPAddress));
|
||||
|
||||
@@ -34,7 +45,7 @@ public class IPv4Box: TemplatedControl
|
||||
get => GetValue(IPAddressProperty);
|
||||
set => SetValue(IPAddressProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly StyledProperty<int> PortProperty = AvaloniaProperty.Register<IPv4Box, int>(
|
||||
nameof(Port));
|
||||
|
||||
@@ -44,32 +55,50 @@ public class IPv4Box: TemplatedControl
|
||||
set => SetValue(PortProperty, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_firstTextPresenter = e.NameScope.Find<TextPresenter>(PART_FirstTextPresenter);
|
||||
_secondTextPresenter = e.NameScope.Find<TextPresenter>(PART_SecondTextPresenter);
|
||||
_thirdTextPresenter = e.NameScope.Find<TextPresenter>(PART_ThirdTextPresenter);
|
||||
_fourthTextPresenter = e.NameScope.Find<TextPresenter>(PART_FourthTextPresenter);
|
||||
_portNumericInput = e.NameScope.Find<NumericUpDown>(PART_PortNumericInput);
|
||||
var box = new TextBox();
|
||||
_firstText = e.NameScope.Find<TextBox>(PART_FirstTextBox);
|
||||
_secondText = e.NameScope.Find<TextBox>(PART_SecondTextBox);
|
||||
_thirdText = e.NameScope.Find<TextBox>(PART_ThirdTextBox);
|
||||
_fourthText = e.NameScope.Find<TextBox>(PART_FourthTextBox);
|
||||
_portText = e.NameScope.Find<TextBox>(PART_PortTextBox);
|
||||
|
||||
_firstText.LostFocus += OnTextLostFocus;
|
||||
}
|
||||
|
||||
private void OnTextKeyDown(object sender, KeyEventArgs args)
|
||||
{
|
||||
if (args.Key == Key.Right)
|
||||
{
|
||||
_secondText?.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTextLostFocus(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
if (sender?.Equals(_firstText)??false)
|
||||
{
|
||||
Debug.WriteLine("FIRST");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Left)
|
||||
{
|
||||
if ((_firstTextPresenter?.IsFocused??false) && _firstTextPresenter.SelectionStart == 0)
|
||||
if ((_firstText?.IsFocused??false) && _firstText.SelectionStart == 0)
|
||||
{
|
||||
_secondTextPresenter?.Focus();
|
||||
_secondText?.Focus();
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Right)
|
||||
{
|
||||
if ((_firstTextPresenter?.IsFocused ?? false) && _firstTextPresenter?.SelectionEnd == 2)
|
||||
if ((_firstText?.IsFocused ?? false) && _firstText?.SelectionEnd == 2)
|
||||
{
|
||||
_firstTextPresenter.Focus();
|
||||
_firstText.Focus();
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Tab)
|
||||
@@ -82,4 +111,13 @@ public class IPv4Box: TemplatedControl
|
||||
}
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
protected override void OnTextInput(TextInputEventArgs e)
|
||||
{
|
||||
if (_firstText != null)
|
||||
{
|
||||
_firstText.Text = e.Text;
|
||||
}
|
||||
base.OnTextInput(e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user