-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TabView: Enable separate lightweight styling of the Add button and the TabViewItem's Close button #2823
TabView: Enable separate lightweight styling of the Add button and the TabViewItem's Close button #2823
Conversation
…w existing TabViewButton* theme resources and applied them in the TabViewButton style.
I think it would be good to also add a sample in the testapp, there already is a TabView where a few resources are changed. Another thing I noticed is that we added the resources for "TabViewItemHeader" + [Pressed,PointerOver,Selected] + "CloseButtonBackground". For completeness, I think we should also add a "TabViewItemHeaderDisabledCloseButtonBackground" resource. Thank you for the detailed explanation of your changes! |
Yes, it's a bit confusing that essentially
Agree with you, since we have the other resources it feels a bit strange to not have that resource too. Good idea!
I am not much of a fan in introducing another test page as we need a way to navigate to that and the test UIs are already hard to use as they are (yes I know I also created a new test page for a TabView PR). However having a complete page dedicated to that seems the best way forward here. |
Adding the theme resource Reason: Currently, as can be seen above, disabled TabViewItems use the background specified by the <StaticResource x:Key="TabViewItemHeaderBackgroundDisabled" ResourceKey="TabViewItemHeaderBackground" /> The idea here is that to keep the existing styling behavior intact, overriding the However, currently, the XAML resource system does not support this level of indirection. Overriding the referenced theme resource ( The missing support in the XAML resource system for this level of indirection has come up a couple of times over the past days (here and here, for example) and should be tracked in its own issue at this point. Anyway, to come back to this PR: I still strongly favor introducing a new |
Having a breaking change is definitely a problem here. However having inconsistent resource names is also not ideal either. Regarding the XAML resource indirection: It's quite unfortunate that that doesn't work. It would allow to introduce a new resource without breaking existing apps. Is there already a proposal/issue for that? If not, would you like to create one? |
Seems like we have to be a bit more precise here as I apparently managed to confuse @StephenLPeters here before when talking about these "UI breaking" changes as "breaking changes". Adding the That said, I would prefer updating WinUI's lightweight styling experiences in a way without causing these kinds of possible design interruptions but they seem to be unavoidable as of now. And speaking of the XAML resource indirection: I am not aware of any open issue about it here in this repo and I plan to to create a tracking issue for it in the next 1-2 days.
I fully agree. At worst, developers simply have to use the newly introduced theme resource here to restore their customized TabViewItem design and in return they will gain greater control over how to design their TabView in all the possible visual state configurations. |
@Felix-Dev Thank you for such a thorough write up and @chingucoding for the indepth discussion. A few things:
Despite the TabView template no longer referencing these resources it is still a breaking change to remove them. For instance if someone retemplated the TabView control their copy of the template would still reference this resouces and if they updated the WinUI version their app would not longer compile if we deleted these. This will not meet the breaking change bar for our WinUI3 release so we will ask that we not make this change in WinUI 2 at this time. Instead, we should leave the resouces in place despite them not being used... :/ The TabViewItemHeaderBackgroundDisabled resource makes sense to me, my vote would be add it. @chigy FYI.
Is the motivation for these just that the current resource name doesn't match the name of the other resources? If so, I think this change would also be a breaking change and would not meet the Winui 3 bar. |
I love this idea, a page that made it easy to change all of the light weight style values of a control and in real time see the effect of that change seems super valuable, not just for Tabview, but probably all of our controls. I wonder if this sort of test page could be generated as well? It seems possible, having a way to change the page to high contrast mode would be cool too. I think we have a habit of not treating the light weight styles as APIs even though that's what they are. |
Agree with Stephen here. We can add new resources, but should avoid changing or removing existing ones which could break the re-templating scenario in WinUI3. We are trying to make the upgrade to WinUI3 as painless as possible. |
I'm fine with leaving them in place for now. Though I would like to add a comment above them in the resource dictionary then, indicating that they are no longer used. Perhaps something like "Note: These theme resources are deprecated and could be removed in a future WinUI update."?
To be clear here: The theme resources
currently do not exist outside of this PR! Removing them would not not be a breaking change then. The story behind these two theme resources is the following: Prior to this PR, the appearance of the TabViewItem's Close button when the TabViewItem is disabled is controlled by the following two theme resources:
In addition, the TabView's Add button also consumes these two theme resources for its disabled appearance. Since this PR is about creating dedicated theme resources for the TabViewItem's Close button and TabView buttons like the Add button, the Close button has to use a new set of resources here. Initially, I just replaced these two resources above with the new
theme resources, while keeping the two theme resources
to be used by the TabView's Add button. Hence achieving the purpose of this PR of having dedicated theme resources (in this case for the disabled states of the Close button and the Add button). However, as @chingucoding and I have discussed above, introducing these two theme resources don't precisely reflect the way the developer can interact with the control. See, these two theme resources are applied when the TabViewItem is disabled. The developer cannot directly set the Close button to disabled. However, the developer can set the TabViewItem to disabled! Theme resources named like Either way, since all the theme resources in question here do not exist prior to this PR, no breaking change would be caused here one way or the other. The deciding point here is just which theme resource names sounds more "logical" from a developer's stand point. So, to recap, we can decide between either
or
Both @chingucoding and me prefer the latter set right now. (That reply went a bit longer than I would have hoped for (and you perhaps expected 😁) but I think this should clearly explain where we are are standing here.) |
Okay, Awesome, I agree with you two, your purposed name seems better. Thank you for the clear explination. @MikeHillberg as the resident naming guru :) |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Since a few days have passed and no other comments arrived, I guess I can go ahead with adding the
theme resources now. |
Sorry for not replying, and thanks for the recap. So |
@MikeHillberg In case the developer grabs the TabViewItem's Close button by walking the visual tree (there is no API exposed on the TabViewItem to directly set the Close button to disabled) and then sets the button to disabled, the That said...the implementation of the TabViewItem.IsClosable API could be changed in the future though (at least in theory) to show a disabled Close button instead of hiding it as done currently. In that case, a theme resource named like |
@Felix-Dev - You said that |
@MikeHillberg Yes, you are reading it correctly. Currently, the PR is using the In this PR, it was suggested to swap out the proposed microsoft-ui-xaml/dev/TabView/TabView.xaml Line 468 in 1bd3129
with the following code: <Setter Target="CloseButton.Background" Value="{ThemeResource TabViewItemHeaderDisabledCloseButtonBackground}" /> While this would provide a more consistent set of theme resources for the TabViewItem with regards to the current TabView implementation, moving the CloseButtonBackgroundDisabled theme resource out of the visual states of the button into the visual states of the TabViewItem would turn into an issue if at some point in the future the Hopefully this gave you a good understanding about where we stand right now in this PR with regards to the proposed |
@Felix-Dev Thanks for the (re-)explanation. Sorry, I got lost in the long thread. In that future feature of a TabView.IsClosable state that disables rather than hides the Close button, could the TabViewItem's existing CloseButtonCollapsed visual state be updated to set CloseButton.Background to TabViewItemHeaderDisabledCloseButtonBackground? (And then not make any visual state updates inside the CloseButton.) |
@MikeHillberg Yes, we could do that. In the case where the TabViewItem.IsClosable API behavior is changed to show a disabled Close button, we should keep in mind though that the background of an enabled TabViewItem with IsClosable = false might be different than the background of a disabled TabViewItem (which would also show a disabled Close button). With the backgrounds potentially differing here, we should probably offer developers with two theme resources here to set the background of the Close button when it's in disabled state: One to cover the case of an enabled TabViewItem which cannot be closed, and the other resource for the case where the entire TabViewItem is disabled. That said, I think we could for now settle on the proposed |
@Felix-Dev That makes sense. Thanks again for explaining. |
…th the TabViewItemHeaderDisabledCloseButton* theme resources.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@teaP would you like to take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize if I'm out of the loop, are these brushes different?
Description
This PR improves the TabView lightweight styling story to enable developers to independently style the appearance of the TabViewItem's Close button and the TabView's Add button. Below is a list of all added, changed and now unused theme resources as part of this PR:
Added theme resources
Reason
Create individual theme resources for the TabViewItem's Close button.
You might notice there are no
TabViewItemHeader**SelectedPointerOver**CloseButtonForeground
andTabViewItemHeader**SelectedPressed**CloseButtonForeground
theme resources for the TabViewItem's Close button listed here. The reason for this is that there are currently no separateTabViewItemHeaderBackgroundSelectedPointerOver
andTabViewItemHeaderBackgroundSelectedPressed
theme resources as can be seen here:microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 438 in 78fa7f6
And here:
microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 451 in 78fa7f6
As such, developers currently cannot use lightweight styling to distinguish the TabViewItem's background while in selected state (the active tab) from its rest mode, its hover mode or its pressed mode. As such, there is also no need to create such theme resources for the Close button right now. If we decide to add the respective
TabViewItemHeaderBackgroundSelectedPointerOver/Pressed
theme resources, we should then also add the corresponding theme resources for the Close button.Changed theme resources
The following theme resources had their values changed as part of this PR:
Reason
Prior to this PR, these theme resources were only used for the TabViewItem's Close button, as can be seen here:
microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 260 in 78fa7f6
And here:
microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 271 in 78fa7f6
The TabView's Add button did not use these theme resources even though it is using the other
TabViewButton*
theme resources. Instead, it used the following theme resources for its Pressed/PointerOver visual states:microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 335 in 78fa7f6
microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 347 in 78fa7f6
As part of this PR, the TabView's Add button now uses these
TabViewButtonBackgroundPressed/PointerOver
andTabViewButtonForegroundPressed/PointerOver
theme resources as well. Thus, to keep the TabView's Add button visual states unchanged in this PR, these four theme resources above have been modified to match the previous theme resources used by the Add button. This is fine because the TabViewItem's Close button which was previously using these resources exclusively now no longer consumes them (see "Added theme resources" section above).Theme resources no longer in use
The following theme resources are no longer in use after this PR. To prevent a breaking change, for now these theme resources have been retained with a note detailing their status:
Reason
The different
TabViewButton*
theme resources are now solely used for the TabView buttons located outside of the TabViewItems, such as the TabView's Add button. As such, there is no concept of an "active tab" for these buttons any longer, thus those theme resources are no longer needed.Additional Info
Additional Info 1
If you checked issue #2655 which this PR is aiming to close, you will notice that I spoke of creating TabView Add button specific theme resources like
TabViewAddButtonBackground
there. However, as you can see, there is no mention of them in this PR. The reason is the following: With theTabView.TabStripHeader
andTabView.TabStripFooter
APIs, additional content can be added to the TabView strip as can be seen in this image:Now, we can use these two APIs to also add additional buttons to the TabStrip. A great example of where that is done for a TabView is Edge UWP:
Notice how all the TabView buttons use the same style (if we ignore the slight difference in button widths in the two left-most buttons compared to the rest). This is something we could also provide to developers in a future PR. My thinking here is this: WinUI currently uses a private
TabViewButtonStyle
to set the design of the TabView's Add button:microsoft-ui-xaml/dev/TabView/TabView.xaml
Line 300 in 78fa7f6
We can make that style "public" by moving it into the TabView_themeresources.xml files and let developers use it for their custom TabStrip buttons added in the TabStripHeader and the TabStripFooter. See, this is the current default design we get by adding buttons without a style:
Result:
Wouldn't it be nice to expose the
TabViewButtonStyle
here so that developers could use it like this?That way, we can easily enable developers to create a unified TabView button design, as seen in Edge UWP.
I think by now you are seeing why I did not want to create
TabViewAddButton*
specific theme resources to be used in a newTabViewAddButtonStyle
. As I believe this is something worth exploring, I decided to let the TabView Add button keep using the existing resources, even though they are not specifically named after the Add button. As the TabViewItem's Close button still got its dedicated theme resources as part of this PR, this PR still fixes issue #2655 as intended.Additional Info 2
With this PR the theme resources
TabViewItemHeaderSelectedCloseButtonForeground
andTabViewItemHeaderSelectedCloseButtonBackground
where added. As their naming indicates, they control the foreground and background appearance of the TabViewItem's Close button when the tab is selected (the active tab). If we want to be really precise with our lightweight styling offering here, we should also add the correspondingtheme resources. These would control the appearance of the Close button in a selected tab when the Close button is in the hover/pressed state. However, adding these theme resources will require additional logic to be added to TabView.cpp so I did not yet touch these.
Conclusion
Let me know what you think here 😀
Motivation and Context
Closes #2655.
How Has This Been Tested?
Tested manually (see below)
Screenshots:
Take a look at the following XAML and resulting look: