@@ -118,7 +118,10 @@ protected virtual void _checkbox_Toggled(object? sender, RoutedEventArgs e)
118118 StateChanged ? . Invoke ( this , EventArgs . Empty ) ;
119119 _textblock . Opacity = ( _checkbox . IsChecked ?? false ) ? 1 : 0.7 ;
120120 SyncToggleItemStatus ( ) ;
121- AccessibilityAnnouncementService . AnnounceToggle ( _textblock . Text , _checkbox . IsChecked ?? false ) ;
121+ if ( _textblock . Text is not null )
122+ {
123+ AccessibilityAnnouncementService . AnnounceToggle ( _textblock . Text , _checkbox . IsChecked ?? false ) ;
124+ }
122125 var cmd = StateChangedCommand ;
123126 if ( cmd ? . CanExecute ( null ) == true )
124127 cmd . Execute ( null ) ;
@@ -133,9 +136,11 @@ protected void SyncToggleItemStatus()
133136 AutomationProperties . SetItemStatus ( _checkbox , state ) ;
134137 // Name with state suffix: guarantees VoiceOver announces state on macOS
135138 // where ToggleSwitch AX role may not expose IsChecked natively
136- string baseName = _textblock . Text ;
139+ string ? baseName = _textblock . Text ;
137140 if ( ! string . IsNullOrEmpty ( baseName ) )
141+ {
138142 AutomationProperties . SetName ( _checkbox , $ "{ baseName } , { state } ") ;
143+ }
139144 }
140145}
141146
@@ -197,6 +202,9 @@ protected override void _checkbox_Toggled(object? sender, RoutedEventArgs e)
197202 StateChanged ? . Invoke ( this , EventArgs . Empty ) ;
198203 _textblock . Opacity = ( _checkbox . IsChecked ?? false ) ? 1 : 0.7 ;
199204 SyncToggleItemStatus ( ) ;
200- AccessibilityAnnouncementService . AnnounceToggle ( _textblock . Text , _checkbox . IsChecked ?? false ) ;
205+ if ( _textblock . Text is not null )
206+ {
207+ AccessibilityAnnouncementService . AnnounceToggle ( _textblock . Text , _checkbox . IsChecked ?? false ) ;
208+ }
201209 }
202210}
0 commit comments