Cockpit: Fokus-Anker 1x1 (0x0 nahm keinen Fokus an), auch beim Aktivieren und mit Esc
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -137,19 +137,36 @@ public sealed partial class MainWindow : Window
|
||||
Wurzel.KeyboardAcceleratorPlacementMode = Microsoft.UI.Xaml.Input.KeyboardAcceleratorPlacementMode.Hidden;
|
||||
// Fokus-Anker (Owner 26.11.: "der Fokus ist permanent im Tisch-Input"): ein Klick irgendwo
|
||||
// ausser in ein Eingabefeld nimmt dem Feld den Fokus, Enter ebenso; beim Start sitzt er hier.
|
||||
var anker = new ContentControl { IsTabStop = true, Width = 0, Height = 0, UseSystemFocusVisuals = false };
|
||||
// 1x1 statt 0x0: ein Element ohne Flaeche nimmt in WinUI keinen Fokus an (26.11.: der Anker wirkte nie)
|
||||
var anker = new ContentControl
|
||||
{
|
||||
IsTabStop = true, Width = 1, Height = 1, Opacity = 0, IsHitTestVisible = false, TabIndex = 0,
|
||||
UseSystemFocusVisuals = false, HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Top
|
||||
};
|
||||
Grid.SetRowSpan(anker, 99);
|
||||
Grid.SetColumnSpan(anker, 99);
|
||||
Wurzel.Children.Add(anker);
|
||||
anker.Loaded += (_, _) => anker.Focus(FocusState.Programmatic);
|
||||
void Weg() => anker.Focus(FocusState.Programmatic);
|
||||
anker.Loaded += (_, _) => Weg();
|
||||
// Beim Aktivieren holt WinUI den letzten Fokus zurueck - in ein Eingabefeld nur, wenn man hineinklickt
|
||||
Activated += (_, e) =>
|
||||
{
|
||||
if (e.WindowActivationState != WindowActivationState.Deactivated && Content?.XamlRoot is { } wurzel
|
||||
&& InEingabe(Microsoft.UI.Xaml.Input.FocusManager.GetFocusedElement(wurzel) as DependencyObject))
|
||||
DispatcherQueue.TryEnqueue(Weg);
|
||||
};
|
||||
Wurzel.AddHandler(UIElement.PointerPressedEvent,
|
||||
new Microsoft.UI.Xaml.Input.PointerEventHandler((_, e) =>
|
||||
{
|
||||
if (!InEingabe(e.OriginalSource as DependencyObject)) anker.Focus(FocusState.Programmatic);
|
||||
if (!InEingabe(e.OriginalSource as DependencyObject)) Weg();
|
||||
}), true);
|
||||
Wurzel.AddHandler(UIElement.KeyDownEvent,
|
||||
new Microsoft.UI.Xaml.Input.KeyEventHandler((_, e) =>
|
||||
{
|
||||
if (e.Key == Windows.System.VirtualKey.Enter && InEingabe(e.OriginalSource as DependencyObject))
|
||||
anker.Focus(FocusState.Programmatic);
|
||||
if ((e.Key == Windows.System.VirtualKey.Enter || e.Key == Windows.System.VirtualKey.Escape)
|
||||
&& InEingabe(e.OriginalSource as DependencyObject))
|
||||
Weg();
|
||||
}), true);
|
||||
Zahnrad.Click += (_, _) => Zeigen(_tag == "einstellungen" ? "cash" : "einstellungen");
|
||||
MenueKnopf.Click += (_, _) => MenueZeigen();
|
||||
|
||||
Reference in New Issue
Block a user