mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 20:54:59 +00:00
ux: auto focus the first input element in popup widget (#49)
This commit is contained in:
parent
ddd152df59
commit
96e60da7ad
45 changed files with 401 additions and 333 deletions
32
src/SourceGit/Views/AutoFocusBehaviour.cs
Normal file
32
src/SourceGit/Views/AutoFocusBehaviour.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Input;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class AutoFocusBehaviour : AvaloniaObject
|
||||
{
|
||||
public static readonly AttachedProperty<bool> IsEnabledProperty =
|
||||
AvaloniaProperty.RegisterAttached<AutoFocusBehaviour, InputElement, bool>("IsEnabled", false, false);
|
||||
|
||||
static AutoFocusBehaviour()
|
||||
{
|
||||
IsEnabledProperty.Changed.AddClassHandler<InputElement>((input, e) =>
|
||||
{
|
||||
if (input.GetValue(IsEnabledProperty))
|
||||
{
|
||||
input.AttachedToVisualTree += (o, _) => (o as InputElement).Focus(NavigationMethod.Directional);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static bool GetIsEnabled(AvaloniaObject elem)
|
||||
{
|
||||
return elem.GetValue(IsEnabledProperty);
|
||||
}
|
||||
|
||||
public static void SetIsEnabled(AvaloniaObject elem, bool value)
|
||||
{
|
||||
elem.SetValue(IsEnabledProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue