-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
XamlC resolves x:DataType incorrectly #11956
Comments
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. |
@StephaneDelcroix thoughts? |
This may have a simpler repro case: #13764 |
Can you give some love (priority) to this issue (I created a duplicated one yesterday the one @mattleibow mentioned) ? From what I see Compiled bindings don't actually work as compiled bindings in MAUI and this issue is 3 months old Thanks |
This comment was marked as off-topic.
This comment was marked as off-topic.
2 similar comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Trying to keep the issue alive :) |
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 3.0(net8). Can repro on Windows platform with sample Project. |
@StephaneDelcroix Can I add this one to your short list? |
I can reproduce the issue with a my comment and repro from #13754 (comment)
|
I wrote a test for 13764 and it looks like this no longer happens (main branch). The observer behavior is as follow
making the page crash on mismatching DataType is NOT an option, as the binding context could change multiple times when parenting the element until the 'right' context is set what are the expectation ? sending a binding diagnostic warning on Debug ? |
I suppose I lumped them all in together because I suppose I expected an exception. But maybe these are 3 separate issues and one is "just add a message". Probably this one is more we need to add some logging or maybe a way to detect this. The generated code is using the type in the XAML, and thus it does not work. Maybe a detection can be added or logs: <!--
This results in an incorrect UI because the DataType on the
DataTemplate is the wrong one.
The generated TypedBinding is using the "incorrect" types:
TypedBinding<SubItem, string>
-->
<Label Text="Incorrect binding, an incorrect DataType:" />
<CollectionView ItemsSource="{Binding Items}" HeightRequest="100">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="local:SubItem">
<Label Text="{Binding Name}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView> This one feels more actionable somehow because of a missing DataType, the inner layer is using the outer type. In this case, the ItemsSource is always (maybe) going to change the binding context of the items. Should there be a way to say that we are using a DataType on an outer layer, so "reset" the type for the inner CV? <!--
This results in an incorrect UI because there is no DataType on the
DataTemplate and XamlC falls back to the DataType on the one above.
The generated TypedBinding is using the incorrect types:
TypedBinding<CollectionItem, string>
-->
<Label Text="Incorrect nested binding, parent DataType:" />
<CollectionView ItemsSource="{Binding Items}" HeightRequest="100">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="local:CollectionItem">
<CollectionView ItemsSource="{Binding SubItems}" HeightRequest="100">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView> This is probably a user error, but I have seen it happen a lot in samples. The DataType attribute is on the ItemTemplate property... shomehow... so should this be a XAMLC error as there is no way to do this in reality? <!--
This results in an incorrect UI because the DataType is not on the
DataTemplate so is ignored.
The generated TypedBinding is using the incorrect types:
TypedBinding<CollectionItem, string>
-->
<Label Text="Incorrect nested binding, parent DataType:" />
<CollectionView ItemsSource="{Binding Items}" HeightRequest="100">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="local:CollectionItem">
<CollectionView ItemsSource="{Binding SubItems}" HeightRequest="100">
<CollectionView.ItemTemplate x:DataType="local:SubItem">
<DataTemplate>
<Label Text="{Binding Name}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView> |
@mattleibow I created this PR that will warn if there's a Binding that inherits the |
Description
This is partly a collection of issues and partly a more specific issue. Not sure if this is 100% a bug in all cases either.
XamlC uses the
x:DataType="<type-name>"
on<DataTemplate>
to generate type-specific bindings, however, somce times the scope is incorrect or if the XAML is wrong but happens to match there is no exception and just fails silently.Steps to Reproduce
Link to public reproduction project repository
https://github.com/mattleibow/maui-bug-repros/blob/repro-xamlc-datatype/MauiApp1/MainPage.xaml
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)
Affected platform versions
All versions
Did you find any workaround?
Make sure the
x:DataType
is specified correctly, and on every level of templates.Relevant log output
No response
The text was updated successfully, but these errors were encountered: