dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.19k stars 1.75k forks source link

Multibindings applied to BindableObject.BindingContext property do not work. #10792

Open bakerhillpins opened 2 years ago

bakerhillpins commented 2 years ago

Description

If a MultiBinding is applied to any BindableObject.BindingContext property the actual bindings in the collection are never evaluated.

For example, Here the bindings to Property1 and Property2 will not be evaluated. Note the Multbinding is applied to the BindingContext property.

            <Label
                Text="{Binding Mode=OneTime}"
                VerticalOptions="Center"
                HorizontalOptions="Center">
                <Label.BindingContext>
                    <MultiBinding Converter="{x:Static converters:MultiBindingPassThroughConverter.Instance}"
                                  FallbackValue="FallbackValue"
                                  TargetNullValue="TargetNullValue">
                        <Binding Path="Property1" Mode="OneTime" />
                        <Binding Path="Property2" Mode="OneTime" />
                    </MultiBinding>
                </Label.BindingContext>
            </Label>

But if the same MultiBinding is moved to the Text property, it works as expected.

            <Label
                VerticalOptions="Center"
                HorizontalOptions="Center">
                <Label.Text>
                    <MultiBinding Converter="{x:Static converters:MultiBindingPassThroughConverter.Instance}"
                                  FallbackValue="FallbackValue"
                                  TargetNullValue="TargetNullValue">
                        <Binding Path="Property1" Mode="OneTime" />
                        <Binding Path="Property2" Mode="OneTime" />
                    </MultiBinding>
                </Label.Text>
            </Label>

Steps to Reproduce

Clone and build the Git Repo linked below. There are 6 different binding scenarios shown and all work except theMultiBinding on the BindingContext property.

Link to public reproduction project repository

https://github.com/bakerhillpins/Issues/tree/NetMauiIssue10792

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

All

Did you find any workaround?

No workaround determined at this time.

Relevant log output

No response

ghost commented 2 years ago

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.

PureWeen commented 2 years ago

@StephaneDelcroix

bakerhillpins commented 1 year ago

Issue:

Not sure why this is being done this way but Bindings, coalesce a context value from several sources and process them.

                object bindingContext = src ?? Context ?? context;

The code above seems to cover for the fact that the context value is set on the binding object here, rather than the BindableObject itself, and thus when ApplyBindings is executed and uses BindableObject.BindingContext it searches for the "correct value". TypedBinding makes this test too.

MultiBinding doesn't do this so it doesn't find anything to bind to.

bakerhillpins commented 1 year ago

I've added a fix for this to the PR above, #12060