Open pekspro opened 1 year ago
Ideally we could just change this line
to use
VisualElement.SetInheritedBindingContext(View, itemBindingContext);
But then that causes the BC to flow from the parent which we don't want.
There's a similar case with this if you look at ContentPresenter where it overrides this
internal override void SetChildInheritedBindingContext(Element child, object context)
{
// We never want to use the standard inheritance mechanism, we will get this set by our parent
}
so that the BC doesn't flow from the parent. We don't really have a place to do this with CV but maybe this can be reworked so the BindableObject can get flagged to ignore the parent BC.
I've updated sample application to .NET 7. The same issue remains, and it also an issue on Android.
Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Windows 11 with below Project: 9131.zip
Issue1: Show nothing for Issue1 in application.
Issue2: Run failed with Error XFC0045 "Binding: Property "Leader" not found on "MauiApp11.Teams"." after adding x:DataType="vm:Teams"
to ContentPage.
Description
I have two issues with
BindingContext
. First issue is that will not set the correctBindingContext
on a ContentView:But this will;
Second issue is that setting a BindingContext from a list is OK. Sample:
This works fine when running an application. But if compiled binding are used, this will not compile.
Steps to Reproduce
ContentView
named PersonView with this XAML content:public record Team (string TeamName, Person Leader);
public record Teams (List TheTeams);
public partial class MainPage : ContentPage { public MainPage() { InitializeComponent();
}
x:DataType="vm:Teams"
in theContentPage
tag.Full sample: https://github.com/pekspro/MauiIssues/tree/9131_BindingContext_cannot_be_changed
Version with bug
6.0.408 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
Windows 10.0.17763.0
Did you find any workaround?
Yes, described in the code.
Relevant log output
No response