-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
area-xamlXAML, CSS, Triggers, BehaviorsXAML, CSS, Triggers, Behaviorst/enhancement ☀️New feature or requestNew feature or request
Milestone
Description
I think XamlC should produce a warning when there is a {Binding ...} inside of a DataTemplate which inherits x:DataType from outside of the template. Consider the following example:
<ScrollView x:DataType="local:PageViewModel">
<StackLayout BindableLayout.ItemsSource="{Binding Items}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</ScrollView>- XamlC won't report any warning
- The
Textproperty will contain aTypedBinding<PageViewModel, PageViewModel>and when the item will have a different type, the label will be empty without producing any warning ([X] do not apply Bindings if DataType doesnt match #22056)
My suggestion is to report a warning something like
XC0024: Binding might be compiled incorrectly because it is using an x:DataType local:PageViewModel that is defined outside of the current DataTemplate scope. Consider adding x:DataType directly to the DataTemplate. See https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information.
... and add a paragraph describing this issue to the linked documentation page.
Related to #22056
ivanpovazan
Metadata
Metadata
Assignees
Labels
area-xamlXAML, CSS, Triggers, BehaviorsXAML, CSS, Triggers, Behaviorst/enhancement ☀️New feature or requestNew feature or request
Type
Projects
Status
Done