@@ -179,6 +179,10 @@ public bool CanFocus
179
179
180
180
if ( ! _canFocus && HasFocus )
181
181
{
182
+ if ( Title == "AdornmentsEditor" )
183
+ {
184
+
185
+ }
182
186
// If CanFocus is set to false and this view has focus, make it leave focus
183
187
// Set traverssingdown so we don't go back up the hierachy...
184
188
SetHasFocusFalse ( null , traversingDown : false ) ;
@@ -381,6 +385,7 @@ public bool HasFocus
381
385
{
382
386
SetHasFocusFalse ( null ) ;
383
387
388
+ Debug . Assert ( ! _hasFocus ) ;
384
389
if ( _hasFocus )
385
390
{
386
391
// force it.
@@ -502,7 +507,6 @@ public bool SetFocus ()
502
507
// Restore focus to the previously focused subview, if any
503
508
if ( ! RestoreFocus ( ) )
504
509
{
505
- // Debug.Assert (_previouslyFocused is null);
506
510
// Couldn't restore focus, so use Advance to navigate to the next focusable subview, if any
507
511
AdvanceFocus ( NavigationDirection . Forward , null ) ;
508
512
}
@@ -656,9 +660,11 @@ private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false
656
660
{
657
661
if ( superViewOrParent . AdvanceFocus ( NavigationDirection . Forward , TabStop ) )
658
662
{
659
- // The above will cause SetHasFocusFalse, so we can return
660
- Debug . Assert ( ! _hasFocus ) ;
661
- return ;
663
+ // The above might have SetHasFocusFalse, so we can return
664
+ if ( ! _hasFocus )
665
+ {
666
+ return ;
667
+ }
662
668
}
663
669
664
670
if ( superViewOrParent is { HasFocus : true , CanFocus : true } )
@@ -709,6 +715,8 @@ private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false
709
715
// No other focusable view to be found. Just "leave" us...
710
716
}
711
717
718
+ Debug . Assert ( _hasFocus ) ;
719
+
712
720
// Before we can leave focus, we need to make sure that all views down the subview-hierarchy have left focus.
713
721
View ? mostFocused = MostFocused ;
714
722
@@ -739,10 +747,17 @@ private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false
739
747
740
748
bool previousValue = HasFocus ;
741
749
750
+ Debug . Assert ( _hasFocus ) ;
751
+
742
752
// Note, can't be cancelled.
743
753
NotifyFocusChanging ( HasFocus , ! HasFocus , this , newFocusedView ) ;
744
754
745
- Debug . Assert ( _hasFocus ) ;
755
+ // Even though the change can't be cancelled, some listener may have changed the focus to another view.
756
+ if ( ! _hasFocus )
757
+ {
758
+ // Notify caused HasFocus to change to false.
759
+ return ;
760
+ }
746
761
747
762
// Get whatever peer has focus, if any so we can update our superview's _previouslyMostFocused
748
763
View ? focusedPeer = superViewOrParent ? . Focused ;
0 commit comments