Skip to content

Conversation

@niels9001
Copy link
Collaborator

@niels9001 niels9001 commented Sep 25, 2025

Fixes: #731

PR Type

What kind of change does this PR introduce?
Bugfix

What is the current behavior?

image

What is the new behavior?

image

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • New component
    • Documentation has been added
    • Sample in sample app has been added
    • Analyzers are passing for documentation and samples
    • Icon has been created (if new sample) following the Thumbnail Style Guide and templates
  • Tests for the changes have been added (if applicable)
  • Header has been added to all new source files
  • Contains NO breaking changes

Other information

@AndrewKeepCoding
Copy link
Contributor

Hi @niels9001!

Just a suggestion. To keep it flexible, we could also implement this in the Disabled visual state.
One caveat: headers using symbol icons appears slightly blurry due to the opacity changes...

<x:Double x:Key="SettingsCardHeaderDisabledOpacity">0.6</x:Double>
<Setter Target="PART_HeaderIconPresenterHolder.Opacity" Value="{StaticResource SettingsCardHeaderDisabledOpacity}" />
image

@niels9001
Copy link
Collaborator Author

niels9001 commented Sep 26, 2025

@AndrewKeepCoding Fair, but we don't check if it's a bitmapicon in that visual state. And we don't want to change the Foreground AND setting the opacity. And we'd want to keep the Foreground on non-image elements to be consistent with other controls and meeting accessibility requirements (e.g. High Contrast themes).

The alternative would be creating a second disabled state?

@AndrewKeepCoding
Copy link
Contributor

I confirmed that an approach like this works.

<VisualStateGroup x:Name="BitmapIconHeaderStates">
    <VisualState x:Name="EnabledBitmapIconHeader" />
    <VisualState x:Name="DisabledBitmapIconHeader">
        <VisualState.Setters>
            <Setter Target="PART_HeaderIconPresenterHolder.Opacity" Value="{StaticResource SettingsCardHeaderDisabledOpacity}" />
        </VisualState.Setters>
    </VisualState>
</VisualStateGroup>

@niels9001
Copy link
Collaborator Author

<x:Double x:Key="SettingsCardHeaderDisabledOpacity">0.6</x:Double>

Yeah, you're right.. that is a more maintainable option :).

Updated the code, please have a look!

@AndrewKeepCoding
Copy link
Contributor

Nit: we could also clean up a few lines:

- using System.ComponentModel.Design;
- IsEnabledChanged += OnIsEnabledChanged;     
+ IsEnabledChanged += OnIsEnabledChanged;
- //  e.Handled = true;

Co-Authored-By: Andrew KeepCoding <andrewkeepcoding@gmail.com>
Co-Authored-By: Andrew KeepCoding <andrewkeepcoding@gmail.com>
Copy link
Contributor

@AndrewKeepCoding AndrewKeepCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad I missed this earlier. Since IsEnabled is checked, we should also refresh the visual state here just to be consistent.

private void CheckInitialVisualState()
{
    VisualStateManager.GoToState(this, IsEnabled ? NormalState : DisabledState, true);

    if (GetTemplateChild("ContentAlignmentStates") is VisualStateGroup contentAlignmentStatesGroup)
    {
        contentAlignmentStatesGroup.CurrentStateChanged -= this.ContentAlignmentStates_Changed;
        CheckVerticalSpacingState(contentAlignmentStatesGroup.CurrentState);
        contentAlignmentStatesGroup.CurrentStateChanged += this.ContentAlignmentStates_Changed;
    }

    // The Disabled visual state will only set the right Foreground brush, but for images we need to lower the opacity so it looks disabled.
    if (HeaderIcon is BitmapIcon)
    {
        VisualStateManager.GoToState(this, IsEnabled ? BitmapHeaderIconEnabledState : BitmapHeaderIconDisabledState, true);
    }
}

@michael-hawker
Copy link
Member

@niels9001 want to address Andrew's last comment? Then I think we're good (though we need to fix CI as GHA runner updated again breaking us... 😭)

@niels9001
Copy link
Collaborator Author

Ah yes,, thanks @AndrewKeepCoding !

Copy link
Contributor

@AndrewKeepCoding AndrewKeepCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.🙂

Copy link
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, fix works as intended with no side effects.

@michael-hawker
Copy link
Member

Re-running job, intermittent RichSuggestBox failure on WinUI 3. FYI @Arlodotexe #589, as I've been mentioning we should disable these specific tests for now (at least on WinUI 3).

@niels9001 niels9001 merged commit a784bad into main Oct 3, 2025
59 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SettingsControls] BitmapIcon does not have a disabled state

4 participants