File tree Expand file tree Collapse file tree 4 files changed +33
-6
lines changed
Expand file tree Collapse file tree 4 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -288,8 +288,8 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
288288
289289 dialogHost . Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) =>
290290 {
291- var child = dialogHost . FocusPopup ( ) ;
292291 CommandManager . InvalidateRequerySuggested ( ) ;
292+ var child = dialogHost . FocusPopup ( ) ;
293293
294294 //https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/issues/187
295295 //totally not happy about this, but on immediate validation we can get some weird looking stuff...give WPF a kick to refresh...
@@ -575,8 +575,14 @@ internal UIElement FocusPopup()
575575 var child = _popup ? . Child ;
576576 if ( child == null ) return null ;
577577
578- child . Focus ( ) ;
579- child . MoveFocus ( new TraversalRequest ( FocusNavigationDirection . Next ) ) ;
578+ CommandManager . InvalidateRequerySuggested ( ) ;
579+ var focusable = child . VisualDepthFirstTraversal ( ) . OfType < UIElement > ( ) . FirstOrDefault ( ui => ui . Focusable && ui . IsVisible ) ;
580+ focusable ? . Dispatcher . InvokeAsync ( ( ) =>
581+ {
582+ if ( ! focusable . Focus ( ) ) return ;
583+ focusable . MoveFocus ( new TraversalRequest ( FocusNavigationDirection . First ) ) ;
584+ } , DispatcherPriority . Background ) ;
585+
580586 return child ;
581587 }
582588
Original file line number Diff line number Diff line change @@ -42,9 +42,8 @@ public void UpdateContent(object content)
4242 _owner . AssertTargetableContent ( ) ;
4343 _owner . DialogContent = content ;
4444 _owner . Dispatcher . BeginInvoke ( DispatcherPriority . Background , new Action ( ( ) =>
45- {
46- _owner . FocusPopup ( ) ;
47- CommandManager . InvalidateRequerySuggested ( ) ;
45+ {
46+ _owner . FocusPopup ( ) ;
4847 } ) ) ;
4948 }
5049
Original file line number Diff line number Diff line change @@ -24,6 +24,27 @@ public static IEnumerable<DependencyObject> VisualDepthFirstTraversal(this Depen
2424 }
2525 }
2626
27+ public static IEnumerable < DependencyObject > VisualBreadthFirstTraversal ( this DependencyObject node )
28+ {
29+ if ( node == null ) throw new ArgumentNullException ( nameof ( node ) ) ;
30+
31+ for ( var i = 0 ; i < VisualTreeHelper . GetChildrenCount ( node ) ; i ++ )
32+ {
33+ var child = VisualTreeHelper . GetChild ( node , i ) ;
34+ yield return child ;
35+ }
36+
37+ for ( var i = 0 ; i < VisualTreeHelper . GetChildrenCount ( node ) ; i ++ )
38+ {
39+ var child = VisualTreeHelper . GetChild ( node , i ) ;
40+
41+ foreach ( var descendant in child . VisualDepthFirstTraversal ( ) )
42+ {
43+ yield return descendant ;
44+ }
45+ }
46+ }
47+
2748 public static bool IsAncestorOf ( this DependencyObject parent , DependencyObject node )
2849 {
2950 return node != null && parent . VisualDepthFirstTraversal ( ) . Contains ( node ) ;
Original file line number Diff line number Diff line change 617617 TextElement.FontSize=" 13"
618618 TextOptions.TextFormattingMode=" Ideal"
619619 TextOptions.TextRenderingMode=" Auto"
620+ FocusManager.IsFocusScope=" True"
620621 Foreground =" {DynamicResource MaterialDesignBody}"
621622 FontFamily =" {StaticResource MaterialDesignFont}"
622623 Focusable =" False"
You can’t perform that action at this time.
0 commit comments