forked from amkovkov/GranuSightSoftware2
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
|
|
using GSS2.ViewModels;
|
|
using GSS2.Views;
|
|
|
|
namespace GSS2.Controls;
|
|
|
|
public class TouchTextBox : TextBox
|
|
{
|
|
protected override Type StyleKeyOverride => typeof(TextBox);
|
|
|
|
public TouchTextBox()
|
|
: base()
|
|
{
|
|
AddHandler(PointerPressedEvent, OnPointerPressed, handledEventsToo: true);
|
|
}
|
|
|
|
private void OnPointerPressed(object? sender, PointerPressedEventArgs ea)
|
|
{
|
|
if (ea.Pointer.Type != PointerType.Touch)
|
|
return;
|
|
var navigation = (Application.Current as Application)?.Navigation;
|
|
if (navigation is null)
|
|
return;
|
|
|
|
var keyboardViewModel = new TextKeyboardViewModel(navigation);
|
|
keyboardViewModel.Value = Text;
|
|
keyboardViewModel.IsMultiline = AcceptsReturn;
|
|
keyboardViewModel.Closes += (_, ea) =>
|
|
{
|
|
if (ea is null)
|
|
return;
|
|
Text = ea;
|
|
};
|
|
var keyboardView = new TextKeyboardView()
|
|
{
|
|
DataContext = keyboardViewModel
|
|
};
|
|
navigation.NavigateTo(keyboardView);
|
|
}
|
|
}
|