@@ -19,15 +19,16 @@ namespace Files.App.Controls
1919 /// </summary>
2020 public partial class ThemedIcon : Control
2121 {
22- private bool _isHighContrast ;
23- private bool _isToggled ;
24- private bool _isEnabled ;
25- private bool _isFilled ;
26- private double _iconSize ;
27-
28- private ToggleButton ? ownerToggleButton = null ;
22+ private bool _isHighContrast ;
23+ private ToggleBehaviors _toggleBehavior ;
24+ private bool _ownerToggled ;
25+ private bool _isEnabled ;
26+ private bool _isFilled ;
27+ private double _iconSize ;
28+
29+ private ToggleButton ? ownerToggleButton = null ;
2930 private AppBarToggleButton ? ownerAppBarToggleButton = null ;
30- private Control ? ownerControl = null ;
31+ private Control ? ownerControl = null ;
3132
3233 public ThemedIcon ( )
3334 {
@@ -152,7 +153,7 @@ private void FindOwnerControlStates()
152153 ownerToggleButton . Checked += OwnerControl_IsCheckedChanged ;
153154 ownerToggleButton . Unchecked += OwnerControl_IsCheckedChanged ;
154155
155- ToggleChanged ( ownerToggleButton . IsChecked is true ) ;
156+ UpdateOwnerToggle ( ownerToggleButton . IsChecked is true ) ;
156157 }
157158
158159 ownerAppBarToggleButton = this . FindAscendant < AppBarToggleButton > ( ) ;
@@ -162,7 +163,7 @@ private void FindOwnerControlStates()
162163 ownerAppBarToggleButton . Checked += OwnerControl_IsCheckedChanged ;
163164 ownerAppBarToggleButton . Unchecked += OwnerControl_IsCheckedChanged ;
164165
165- ToggleChanged ( ownerAppBarToggleButton . IsChecked is true ) ;
166+ UpdateOwnerToggle ( ownerAppBarToggleButton . IsChecked is true ) ;
166167 }
167168
168169 ownerControl = this . FindAscendant < Control > ( ) ;
@@ -182,9 +183,9 @@ private void OwnerControl_IsCheckedChanged(object sender, RoutedEventArgs e)
182183 return ;
183184
184185 if ( ownerToggleButton is not null )
185- ToggleChanged ( ownerToggleButton . IsChecked is true ) ;
186+ UpdateOwnerToggle ( ownerToggleButton . IsChecked is true ) ;
186187 else if ( ownerAppBarToggleButton is not null )
187- ToggleChanged ( ownerAppBarToggleButton . IsChecked is true ) ;
188+ UpdateOwnerToggle ( ownerAppBarToggleButton . IsChecked is true ) ;
188189 }
189190
190191 private void OwnerControl_IsEnabledChanged ( object sender , DependencyPropertyChangedEventArgs e )
@@ -196,10 +197,17 @@ private void OwnerControl_IsEnabledChanged(object sender, DependencyPropertyChan
196197 EnabledChanged ( ownerControl . IsEnabled ) ;
197198 }
198199
199- private void ToggleChanged ( bool value )
200+ private void ToggleBehaviorChanged ( ToggleBehaviors value )
200201 {
201202 // Handles the IsToggled property change
202- _isToggled = value ;
203+ _toggleBehavior = value ;
204+
205+ UpdateVisualStates ( ) ;
206+ }
207+
208+ private void UpdateOwnerToggle ( bool isToggled )
209+ {
210+ _ownerToggled = isToggled ;
203211
204212 UpdateVisualStates ( ) ;
205213 }
@@ -256,14 +264,14 @@ private void HighContrastChanged(bool value)
256264 private void InitialIconStateValues ( )
257265 {
258266 _isEnabled = IsEnabled ;
259- _isToggled = IsToggled ;
267+ _toggleBehavior = ToggleBehavior ;
260268 _isHighContrast = IsHighContrast ;
261269 _iconSize = IconSize ;
262270 }
263271
264272 private void UpdateIconStates ( )
265273 {
266- ToggleChanged ( _isToggled ) ;
274+ ToggleBehaviorChanged ( _toggleBehavior ) ;
267275 EnabledChanged ( _isEnabled ) ;
268276 HighContrastChanged ( _isHighContrast ) ;
269277 }
@@ -277,79 +285,108 @@ private void UpdateVisualStates()
277285
278286 private void UpdateIconTypeStates ( )
279287 {
280- /*
281288 // Handles changes to the IconType and setting the correct Visual States.
282289
283- // Handles the two IconType states, based on the ThemedIcon.IconType value
284- // as well as states derived from owner controls, and other properties
285-
286- // We first check for isToggled and isFilled icon types and states
287- // Then we check for Contrast and Disabled states, to replace Layered with Outline and set EnabledStates
288- // Finally we assigned Filled and Layered states, and default otherwise to Outline
289- */
290-
291- if ( _isToggled is true || IsToggled is true || _isFilled is true || IsFilled is true )
292- {
293- VisualStateManager . GoToState ( this , FilledTypeStateName , true ) ;
294- return ;
295- }
296- else if ( _isHighContrast is true || IsHighContrast is true || _isEnabled is false || IsEnabled is false )
297- {
298- VisualStateManager . GoToState ( this , OutlineTypeStateName , true ) ;
299- VisualStateManager . GoToState ( this , DisabledStateName , true ) ;
300- return ;
301- }
302- else
303- {
304- if ( IconType == ThemedIconTypes . Layered )
305- {
306- VisualStateManager . GoToState ( this , LayeredTypeStateName , true ) ;
307- }
308- else
309- {
310- VisualStateManager . GoToState ( this , OutlineTypeStateName , true ) ;
311- }
312- }
290+ // If ToggleBehavior is Auto, we check for _ownerToggle
291+ if ( _toggleBehavior == ToggleBehaviors . Auto )
292+ {
293+ if ( _ownerToggled is true || _isFilled is true || IsFilled is true )
294+ {
295+ VisualStateManager . GoToState ( this , FilledTypeStateName , true ) ;
296+ return ;
297+ }
298+ else if ( _isHighContrast is true || IsHighContrast is true || _isEnabled is false || IsEnabled is false )
299+ {
300+ VisualStateManager . GoToState ( this , OutlineTypeStateName , true ) ;
301+ VisualStateManager . GoToState ( this , DisabledStateName , true ) ;
302+ return ;
303+ }
304+ else
305+ {
306+ if ( IconType == ThemedIconTypes . Layered )
307+ {
308+ VisualStateManager . GoToState ( this , LayeredTypeStateName , true ) ;
309+ }
310+ else
311+ {
312+ VisualStateManager . GoToState ( this , OutlineTypeStateName , true ) ;
313+ }
314+ }
315+ }
316+ // If ToggleBehavior is On, we only go to Filled.
317+ else if ( _toggleBehavior == ToggleBehaviors . On )
318+ {
319+ VisualStateManager . GoToState ( this , FilledTypeStateName , true ) ;
320+ }
321+ // For Off, we don't respond to _ownerToggle at all
322+ else
323+ {
324+ if ( _isFilled is true || IsFilled is true )
325+ {
326+ VisualStateManager . GoToState ( this , FilledTypeStateName , true ) ;
327+ return ;
328+ }
329+ else if ( _isHighContrast is true || IsHighContrast is true || _isEnabled is false || IsEnabled is false )
330+ {
331+ VisualStateManager . GoToState ( this , OutlineTypeStateName , true ) ;
332+ VisualStateManager . GoToState ( this , DisabledStateName , true ) ;
333+ return ;
334+ }
335+ else
336+ {
337+ if ( IconType == ThemedIconTypes . Layered )
338+ {
339+ VisualStateManager . GoToState ( this , LayeredTypeStateName , true ) ;
340+ }
341+ else
342+ {
343+ VisualStateManager . GoToState ( this , OutlineTypeStateName , true ) ;
344+ }
345+ }
346+ }
313347
314348 VisualStateManager . GoToState ( this , EnabledStateName , true ) ;
315349 }
316350
317351 private void UpdateIconColorTypeStates ( )
318352 {
319- /*
320353 // Handles changes to the IconColorType and setting the correct Visual States.
321354
322- // We first check if the Icon is Disabled
323- // Then we check if the Disabled Icon is Toggled
324-
325- // We then assume the Icon is Enabled
326- // We then check the Toggled state for the Contrast Icons
327- // We have two states depending on toggle.
328-
329- // Finally we act on all other Enabled states
330- // We check for Toggled state
331- // And update the IconColorType in the Layered Icon's Layers
332- */
333-
355+ // First we check the enabled state
334356 if ( _isEnabled is false || IsEnabled is false )
335357 {
336- if ( _isToggled is true || IsToggled is true )
337- {
338- VisualStateManager . GoToState ( this , DisabledToggleColorStateName , true ) ;
339- }
340- else
341- {
342- VisualStateManager . GoToState ( this , DisabledColorStateName , true ) ;
343- }
358+ // If ToggleBehavior is Auto and _ownerToggled is true
359+ if ( _toggleBehavior == ToggleBehaviors . Auto && _ownerToggled is true )
360+ {
361+ VisualStateManager . GoToState ( this , DisabledToggleColorStateName , true ) ;
362+ }
363+ // If ToggleBehavior is On
364+ else if ( _toggleBehavior == ToggleBehaviors . On )
365+ {
366+ VisualStateManager . GoToState ( this , DisabledToggleColorStateName , true ) ;
367+ }
368+ // everything else uses Disabled Color
369+ else
370+ {
371+ VisualStateManager . GoToState ( this , DisabledColorStateName , true ) ;
372+ }
344373 }
374+ // Everything else is Enabled
345375 else
346376 {
347- if ( _isToggled is true || IsToggled is true )
348- {
377+ // If ToggleBehavior is Auto and _ownerToggled is true
378+ if ( _toggleBehavior == ToggleBehaviors . Auto && _ownerToggled is true )
379+ {
349380 VisualStateManager . GoToState ( this , ToggleStateName , true ) ;
350381 }
351- else
352- {
382+ // If ToggleBehavior is On
383+ else if ( _toggleBehavior == ToggleBehaviors . On )
384+ {
385+ VisualStateManager . GoToState ( this , ToggleStateName , true ) ;
386+ }
387+ // everything else uses the appropriate color state
388+ else
389+ {
353390 VisualStateManager . GoToState (
354391 this ,
355392 IconColorType switch
0 commit comments