Skip to content

Fix regression bug with application title no longer grayed out.#632

Merged
HowardWolosky merged 1 commit intomicrosoft:masterfrom
rudyhuyn:FixRegressionTitleGray
Aug 19, 2019
Merged

Fix regression bug with application title no longer grayed out.#632
HowardWolosky merged 1 commit intomicrosoft:masterfrom
rudyhuyn:FixRegressionTitleGray

Conversation

@rudyhuyn
Copy link
Copy Markdown
Contributor

@rudyhuyn rudyhuyn commented Aug 7, 2019

Fixes #631

Description of the changes:

  • Move back the VisualStateManager node to the root XAML element to fix visual states of the titlebar.

How changes were validated:

  • Manually

Copy link
Copy Markdown
Contributor

@HowardWolosky HowardWolosky left a comment

Choose a reason for hiding this comment

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

Thanks Rudy.
While I do agree that after testing, this does fix the problem, it's not clear to me why this fixes the problem, nor why the previous change introduced the problem in the first place.

Any chance that you can explain for myself (and the rest of our readers here)?

@HowardWolosky HowardWolosky self-assigned this Aug 19, 2019
@rudyhuyn
Copy link
Copy Markdown
Contributor Author

Any chance that you can explain for myself (and the rest of our readers here)?

Of course!

The attached property VisualStateManager.VisualStateGroups can only be attached to the root XAML node of the control's content to work with VisualStateManager::GoToState(...), else it won't work (hard to detect because it won't crash the app or display an error/warning at compilation time).

The previous change added an additional grid (BackgroundElement) moving by accident the VisualStateManager out of the root node and making VisualStateManager::GoToState ineffective.
image.

@HowardWolosky
Copy link
Copy Markdown
Contributor

Thanks @rudyhuyn.

The attached property VisualStateManager.VisualStateGroups can only be attached to the root
XAML node of the control's content
to work with VisualStateManager::GoToState(...), else it won't
work (hard to detect because it won't crash the app or display an error/warning at compilation
time).

That was what I figured based on your change. Thanks for the confirmation. I then found corresponding documentation to support that statement as well:

https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.VisualStateManager#remarks

Control authors or app developers add VisualStateGroup object elements to the root element of a
control template definition in XAML, using the VisualStateManager.VisualStateGroups attached
property.

But then I'm trying to understand other places where it appears to not be on the root XAML node of the control. Take for example,, the TitleContentControl:

<ContentControl x:Name="TitleContentControl"
Margin="{StaticResource PivotPortraitThemePadding}"
Style="{StaticResource TitleContentControlStyle}"
Content="{TemplateBinding Title}"
ContentTemplate="{TemplateBinding TitleTemplate}"
IsTabStop="False"
Visibility="Collapsed"/>
<Grid Grid.Row="1">
<Grid.Resources>
<ControlTemplate x:Key="NextTemplate" TargetType="Button">
<Border x:Name="Root"
Background="{ThemeResource PivotNextButtonBackground}"
BorderBrush="{ThemeResource PivotNextButtonBorderBrush}"
BorderThickness="{ThemeResource PivotNavButtonBorderThemeThickness}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">

Here we have a Grid which contains a Border, and the VisualStateMananger.VisualStateGroups is on the Border as opposed to the Grid element which should in theory be considered the root node.

I think your change here is completely right, no doubt. I'm just trying to wrap my head around some inconsistent usage (as far as I can tell) of VSM then within the project (although, as far as I can tell, this is the only other example in the project besides the one in this PR where VSM isn't attached to the root node).

Thoughts?

@rudyhuyn
Copy link
Copy Markdown
Contributor Author

rudyhuyn commented Aug 19, 2019

Here we have a Grid which contains a Border, and the VisualStateMananger.VisualStateGroups is on the Border as opposed to the Grid element which should in theory be considered the root node.

Even if the Border is a X(A)ML descendant of the Grid, they are not related and are part of 2 different XAML trees because the ContentTemplate has its own XAML tree structure.

The Grid is a content of the Page, and is part of its visual tree.
The Border isn't part of the visual tree but part of the template definition describing a Button and is the root node of this definition. (defined in Grid Resources).

So the definition is still correct: the VisualStateManager is attached to the root element of a control template.

image

@HowardWolosky
Copy link
Copy Markdown
Contributor

Ah. Good catch. I completely missed that there was a ControlTemplate embedded within the ContentControl there. Thanks for looking into all of this.

@HowardWolosky HowardWolosky merged commit 5966503 into microsoft:master Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The app title is no longer grayed out when the application loses focus

3 participants