Open bebenlebricolo opened 9 months ago
Yes, I have face the same. +1
Also seeing this with a slight variation. Even if there is a dataType specified it can still not show the label if the dataType is incorrect (which is user error, but still works for debug, and not release).
For example,
<CollectionView ItemsSource="{Binding MenuItems}" IsGrouped="True">
<CollectionView.GroupHeaderTemplate>
<DataTemplate x:DataType="models:Item">
<Label TextColor="Black" BackgroundColor="White" Text="{Binding Name}" />
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border>
<Label Text="{Binding .}" TextColor="White" BackgroundColor="BlueViolet"/>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
View Model and Other classes:
public partial class MainPageViewModel : ObservableObject
{
[ObservableProperty]
private ObservableCollection<MenuCategory> menuItems = [];
public MainPageViewModel() {
menuItems =
[
new("Group 1", [new("One", "1"), new("Two", "2"), new("Three", "3")]),
new("Group 2", [new("1", "11"), new("2", "22"), new("3", "33")])
];
}
}
public record Item(string Name, string Other);
public class MenuCategory(string name, IReadOnlyCollection<Item> items) : ObservableCollection<Item>(items)
{
public string Name { get; private set; } = name;
}
In this case, both Item
and MenuCategory
have a property name and so compile fine, no intellisense errors. But the header template is really of type MenuCategory
but we specified Item
, so even though Item
compiles and builds fine, the labels are blank in release, but show fine in debug mode.
Can repro this issue at Android platform on the latest 17.10.0 Preview 2.0(8.0.14/8.0.3) with sample project.
@D-Parkinson1 issue (and other mismatching behaviour between debug/release) fixed by #22056
Description
[Appears on Android, physical and emulator devices]
DataBinding don't seem to fully work in
<DataTemplate></DataTemplate>
ifx:DataType="customenamespace:MyDataModel"
is not explicitely specified as DataTemplate property. More specifically, events are well propagated and properties properly propagate the updates to the code-behind.However, it seems
DataTemplate
is missing the Type information in release mode (which is conveyed fine in Debug builds). Hence, the controls within theDataTemplate
tag are bound, but they can't access the data they need to display. This is true for POD and for functions (I had app crashes when clicking on an item of theCollectionView
in release mode without theDataType
property, probably because the event function couldn't be found).In-situ app demonstration :
With the
DataType
property :Without the DataType property :
Here is the code snippet which is responsible for this :
As you can see, all properties (
Labels
here) are missing from the render. Furthermore, as said, when I click on a card, it normally navigates (with the Shell) to a new page where we can find details about the selected item. This relies on aRelayCommand
which is bound to the ViewModel. In Debug mode, this works fine. In Release mode with theDataType
property, it also works fine. In Release mode without theDataType
property, it crashes.Steps to Reproduce
Link to public reproduction project repository
https://github.com/bebenlebricolo/DotnetMaui-DataTemplateBug
Version with bug
8.0.6
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Api levels 30 to 34 at least (Android 11 and above)
Did you find any workaround?
Explicitely specify
x:DataType
information asDataTemplate
propertyRelevant log output
No response