Skip to content

BindingContext Not Propagated Correctly to ContentView When ControlTemplate Changes at Runtime #25934

@s-beltz

Description

@s-beltz

Description

We are using AdaptiveTrigger to dynamically adjust the ControlTemplate of a ContentView based on screen size, ensuring an optimal layout for various devices.

Following the workaround detailed in this issue, we were able to implement this approach successfully up to .NET 9 RC2. However, after upgrading to the final release of .NET 9, this solution no longer works.

The issue occurs when the ControlTemplate is changed at runtime (e.g., via AdaptiveTrigger or OnSizeChanged). While the initial ControlTemplate is applied correctly with the expected BindingContext, any subsequent changes to the template cause the BindingContext to be lost. Once lost, the BindingContext does not reapply, resulting in broken bindings.

Unfortunately, we have not identified any workaround for this issue, which blocks us from shipping our product.

Is there any guidance or known workaround to resolve this? Any help would be greatly appreciated! 😊

Steps to Reproduce

We have created a repro project to demonstrate the issue:
controltemplate-repro.zip

On Windows, resizing the window triggers a ControlTemplate change and reproduces the problem. On Android and iOS, the issue can be observed on phone-sized simulators where the smaller screen size causes the ControlTemplate to change. However, tablet-sized simulators (which do not trigger a template change) work as expected.

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.0-rc.2.24503.2

Affected platforms

iOS, Android, Windows

Affected platform versions

No response

Did you find any workaround?

Unfortunately not... ;-(

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions