mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-20 07:39:09 +08:00
Refactor(Cascader): Add basic key handle support
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Reactive.Disposables.Fluent;
|
||||
using AtomUI.Controls;
|
||||
using AtomUI.Desktop.Controls.DataLoad;
|
||||
using AtomUI.Desktop.Controls.Primitives;
|
||||
using AtomUI.Input;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
@@ -273,6 +274,57 @@ public class Cascader : AbstractSelect, IControlSharedTokenResourcesHost
|
||||
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
_ = e ?? throw new ArgumentNullException(nameof(e));
|
||||
base.OnKeyDown(e);
|
||||
if (e.Handled || !IsEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsDropDownOpen)
|
||||
{
|
||||
if (_cascaderView != null)
|
||||
{
|
||||
_cascaderView.HandleKeyDown(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The drop down is not open, the Down key will toggle it open.
|
||||
// Ignore key buttons, if they are used for XY focus.
|
||||
if (e.Key == Key.Down
|
||||
&& !this.IsAllowedXYNavigationMode(e.KeyDeviceType))
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Standard drop down navigation
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.F4:
|
||||
SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
|
||||
e.Handled = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
@@ -644,4 +644,26 @@ public partial class CascaderView : TemplatedControl, IMotionAwareControl, ICont
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void HandleKeyDown(KeyEventArgs e)
|
||||
{
|
||||
// TODO
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Enter:
|
||||
e.Handled = false;
|
||||
break;
|
||||
|
||||
case Key.Up:
|
||||
e.Handled = false;
|
||||
break;
|
||||
|
||||
case Key.Down:
|
||||
e.Handled = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -643,7 +643,7 @@ public class AbstractSelect : TemplatedControl, IMotionAwareControl, ISizeTypeAw
|
||||
|
||||
private void HandleWindowDeactivated(object? sender, EventArgs e)
|
||||
{
|
||||
//SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user