Skip to content
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

ControlTemplate not propagating the BindingContext correctly #12470

Closed
ivan-todorov-progress opened this issue Jan 6, 2023 · 1 comment · Fixed by #12536
Closed

ControlTemplate not propagating the BindingContext correctly #12470

ivan-todorov-progress opened this issue Jan 6, 2023 · 1 comment · Fixed by #12536
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 t/bug Something isn't working
Milestone

Comments

@ivan-todorov-progress
Copy link

Description

The bug manifests itself when using a ContentView with a custom ControlTemplate. For some reason, the BindingContext is not propagated to the children created with the ControlTemplate. This makes it impossible to use regular data binding in the ControlTemplate. For example, let's consider the following trivial scenario:

<VerticalStackLayout>
    <Label Text="{Binding Text}" />
    <ContentView>
        <ContentView.ControlTemplate>
            <ControlTemplate>
                <Label Text="{Binding Text}" />
            </ControlTemplate>
        </ContentView.ControlTemplate>
    </ContentView>
</VerticalStackLayout>

The first Label that is placed directly in the VerticalStackLayout displays the Text property form the BindingContext correctly. The second Label that is created from the ControlTemplate does not display anything at all.

Steps to Reproduce

  1. Run the provided sample project
  2. Observe the text of the two Labels
  • The first Label displays the text correctly
  • The second Label from the ControlTemplate is empty

Link to public reproduction project repository

https://github.com/ivan-todorov-progress/maui-control-template-binding-context-bug

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

N/A

Did you find any workaround?

The workaround is to propagate the BindingContext manually, e.g.:

<ControlTemplate>
    <Label Text="{Binding Text}" BindingContext="{Binding BindingContext, Source={RelativeSource Mode=TemplatedParent}}" />
</ControlTemplate>

Relevant log output

No response

@ivan-todorov-progress ivan-todorov-progress added the t/bug Something isn't working label Jan 6, 2023
@jsuarezruiz jsuarezruiz added area-xaml XAML, CSS, Triggers, Behaviors partner Issue or Request from a partner team labels Jan 9, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jan 9, 2023
@ghost
Copy link

ghost commented Jan 9, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jsuarezruiz jsuarezruiz self-assigned this Jan 9, 2023
@mikeparker104 mikeparker104 added the partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with label Feb 2, 2023
@samhouts samhouts added p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint and removed p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint labels Feb 3, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! label Feb 22, 2023
@samhouts samhouts modified the milestones: Backlog, 8.0-preview1 Feb 22, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants