TabViewItem: Respect Background & Foreground APIs#3769
Conversation
| Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "TabView_APITests", "dev\TabView\APITests\TabView_APITests.shproj", "{2F4E95E9-F729-481C-B9AA-C9BEC91AE395}" | ||
| EndProject |
There was a problem hiding this comment.
Aren't those changes that I would revert anytime I am using the innerloop without TabView?
There was a problem hiding this comment.
This in a permanent change which adds the TabView's API test project to the innerloop solution (missing yet in VS).
On that note, it might be better to make this a separate commit to the master branch depending on how long it will take to merge this PR into master. Otherwise, we could end up seeing multiple TabView PRs which modify the API test project and each would then have the to make the same changes -- if the contributor uses the innerloop.
There was a problem hiding this comment.
I think that that change makes more sense to have given that this PR might take some time and contributors would be left without those changes until then. In addition to that, it's also only related to the bug you are fixing in the sense that it is the same control, not much more.
There was a problem hiding this comment.
We already have at least two outstanding TabView PRs which add the missing API test project to the innerloop solution so the situation is already less than ideal. I will create a standalone PR for this in the next few minutes.
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| // If Foreground is set, then change icon and header foreground to match. | ||
| winrt::VisualStateManager::GoToState( | ||
| *this, | ||
| ReadLocalValue(winrt::Control::ForegroundProperty()) == winrt::DependencyProperty::UnsetValue() ? L"ForegroundNotSet" : L"ForegroundSet", |
There was a problem hiding this comment.
@jevansaks how do we feel about this these days?
There was a problem hiding this comment.
@jevansaks or @MikeHillberg Wanting to clear some of these old PRs out. Is DP::UnsetValue acceptable to use? I know there was some contention on this in the past.
There was a problem hiding this comment.
Properties in general don't have an "is set" concept. Properties that are implemented with a DependencyProperty appear to have one, do to DP.UnsetValue. But this code example is only seeing if the local value is set or not, rather than checking of the property is being set by any means. For example, maybe the property is "set", but it's set by a Style.
For properties we want to have some kind of unset state we usually talk about sentinel values. For reference types that's usually null, for value types we frequently use Nullable to make it a reference type, and sometimes we use magic values like -1, min/max-infinity, or Nan. (Nullable is the better API choice.)
Is there some other condition we can use here?
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Please, is there anything Terminal can do to help move this along? What's remaining? We have so much code that manually patches resources on TabViewItems because we cannot do this. 😄 |
|
Just to clarify, will this PR make it so the Terminal doesn't need to do this crazy stuff to change the background color of a |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Related question: when setting the background with these APIs, will it also update the rounded corners on the bottoms, like in microsoft/terminal#7133? |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hey I'm trying to ingest this over on the Terminal side, and just wanted to make sure I wasn't doing anything wrong. You can see where I replaced our manual color replacement here: microsoft/terminal@d112bd9 Which ends up looking like this:
Is this all expected? |
|
I think it is. Brushes for each state need to be set manually, and this API only does it for the unselected state. This is also why the foreground remains black on dark backgrounds. There isn't really something to handle that. There would need to be a style that would take the tab color and create a foreground brush. |
* this is the same thing as #10996, but with the fix that caused us to #11031 * This includes microsoft/microsoft-ui-xaml#3769, so we had to make some adjustments to how we handle tab colors. It works the same as before. * Should enable #11231 to be started * [x] Closes #10508 * [x] Closes #7133 * [x] Closes #8948 * [ ] I need to finish letting my 19H1 VM boot to make sure unpackaged still works
DESPITE the fact that there's a `Background()` API that we
could just call like:
```c++
TabViewItem().Background(deselectedTabBrush);
```
We actually can't, because it will make the part of the tab that
doesn't contain the text totally transparent to hit tests. So we
actually _do_ still need to set `TabViewItemHeaderBackground` manually.
* Regressed in #11240
* Root cause up in microsoft/microsoft-ui-xaml#3769
* [x] closes #11294
DESPITE the fact that there's a `Background()` API that we could just call like: ```c++ TabViewItem().Background(deselectedTabBrush); ``` We actually can't, because it will make the part of the tab that doesn't contain the text totally transparent to hit tests. So we actually _do_ still need to set `TabViewItemHeaderBackground` manually. * Regressed in #11240 * Root cause up in microsoft/microsoft-ui-xaml#3769 * [x] closes #11294



Description
This PR supersedes PR #3216. The main difference between these two PRs is the following: We no longer retire the existing
TabViewItemIcon[...]theme resources. Instead, we follow the API design set by the InfoBar which ships theme resources to provide fine-grained customization options yet also utilizes theForegroundAPI to provide a "customize-all-at-once" option. The relevant discussion leading to this change in API design (and thus this new PR) can be found starting here.Example: Setting the
TabViewItem.Foregroundbrush will change the foreground of the TabViewItem's icon and header accordingly. If, however, customers want to individually style the icon and header foreground in rest mode, they can use the existingTabViewItemIconForegroundandTabViewItemHeaderForegroundtheme resources instead. See the XAML markup below and the resulting UI.And here is an additional GIF showcasing the behavior:

Note that as with the InfoBar control, the
ForegroundAPI takes precendence over the theme resources mentioned above. If the Foreground property is not set (or has been cleared) then the theme resources mentioned above are utilized.Last but not least, the
TabViewItemHeaderBackgroundtheme resource is used by default to set the header background of a TabViewItem, but customers can assign a new brush to the TabViewItem.Background property which will then be used instead.Additional remarks
VerifyTabViewItemHeaderForegroundResource()(alongside the relevant elements in the test UI) has been removed as it is now covered by the newly addedTabViewItemForegroundTest()API test.@stmoy @StephenLPeters @DHowett FYI.
Motivation and Context
Fixes #2653
How Has This Been Tested?
Tested manually and added API tests.