Skip to content

Fix ContentDialog entrance animation not playing with OptimizeApplyStyles - #11736

Open
Mike Crider (codendone) wants to merge 1 commit into
mainfrom
user/codendone/fixContentDialogWithOptimizeApplyStyles
Open

Fix ContentDialog entrance animation not playing with OptimizeApplyStyles#11736
Mike Crider (codendone) wants to merge 1 commit into
mainfrom
user/codendone/fixContentDialogWithOptimizeApplyStyles

Conversation

@codendone

Copy link
Copy Markdown
Contributor

Fix problem where ContentDialog entrance animation commonly won't play with the OptimizeApplyStyles optional change enabled.

Fixes

Fixes #11257

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Description

Current Behavior

Under OptimizeApplyStyles, a CControl's built-in style (which supplies the control's Template) is applied lazily only when the control goes live (CreationComplete / EnterImpl). ContentDialog::ShowAsync explicitly calls ApplyTemplate() on the not-yet-live dialog, so GetTemplate() returned null, the template wasn't expanded, and named template parts (LayoutRoot / SmokeLayerBackground) resolved late once the dialog went live. That late resolution triggered a second HostDialogWithinPopup re-parent, which cancelled the ContentDialogOpenCloseThemeTransition entrance animation.

New Behavior

Add a CControl::ApplyTemplate override that ensures the built-in style is applied before the base class expands the template. With the style always applied, the associated entrance animation correctly plays.

Tests for performance shows the original performance fix is still effective in avoiding unnecessary style application.

Customer Impact

Enabling the OptimizeApplyStyles optional change prior to this fix causes a regression. With this fix, apps are free to enable that performance optimization without this regression.

Regression Potential

  • Low risk — isolated change, limited scope
  • Medium risk — touches shared components or public APIs
  • High risk — architectural or breaking API change

How Has This Been Tested?

  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • Existing tests pass locally

…yles (GitHub #11257)

Under OptimizeApplyStyles, a CControl's built-in style (which supplies the control's Template) is applied lazily only when the control goes live (CreationComplete / EnterImpl). ContentDialog::ShowAsync explicitly calls ApplyTemplate() on the not-yet-live dialog, so GetTemplate() returned null, the template wasn't expanded, and named template parts (LayoutRoot / SmokeLayerBackground) resolved late once the dialog went live. That late resolution triggered a second HostDialogWithinPopup re-parent, which cancelled the ContentDialogOpenCloseThemeTransition entrance animation.

Add a CControl::ApplyTemplate override that ensures the built-in style is applied before the base class expands the template. Factor the theme-guarded style application shared with EnterImpl into EnsureBuiltInStyleApplied(), which no-ops once the style has already been applied so compat mode and already-live controls are unaffected.
@codendone
Mike Crider (codendone) requested a review from a team as a code owner August 31, 2026 23:46
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the needs-triage Issue needs to be triaged by the area owners label Aug 31, 2026
@codendone

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.

hoshiizumiya added a commit to hoshiizumiya/OpenNet that referenced this pull request Sep 1, 2026
Added detailed IPv4/IPv6 TCP/UDP port reachability status to main view and NAT detector, including new UI flyouts and quick port test.
Refactored detection logic for independent protocol probing, improved timeout/evidence reporting, and parallel checks.
Enhanced NATDetectorWindow to show endpoints, per-protocol results, and RFC 5780 filtering.
MainViewModel now refreshes port state per protocol/address family on a dedicated thread.
Updated README with build requirements and clarified Windows 10 support.
Improved error handling, concurrency, and UI responsiveness.
Sync: lgztx96/CommunityToolkit.WinUI@0a6bf76
Add XamlResource in the App.xaml to mitigate the Dialog custom style setting regression - microsoft/microsoft-ui-xaml#11736
{
if (OptionalChangeState::IsOptimizeApplyStylesEnabled())
{
IFC_RETURN(EnsureBuiltInStyleApplied());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We seem to apply only the built-in style here, while any explicit or implicit Style still lands later in EnterImpl. If that style carries a different ControlTemplate, the template we expand now gets torn down and expanded again, so OnApplyTemplate runs twice and we may hit the same reparenting problem this change is trying to avoid. The new test uses DefaultContentDialogStyle, which resolves to the same ControlTemplate as the built-in style, so it probably won't catch this. Please check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ok

@gegao18 George Gao (gegao18) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-triage Issue needs to be triaged by the area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: ContentDialog without animation when XamlChangeId.OptimizeApplyStyles enabled

4 participants