I have a collection view with an external view for the DataTemplate
. The views show for the CollectionView
with the data correctly bound (it’s not using a VM fas it’s simple app). The data model that fills the CollectionView
contans a property called Id
(an int). This is fed as the ClassId
for the Frame
within the ContentView
used by the DataTemplate
.
I’ve added a SelectionChanged
event to the CollectionView
which fires fine. However, when I examine the object passed in, it looks like the ClassId
is not being propogagated to the ContentView
selected.
My code in the event looks like this
void ItemSelected_Clicked(object? sender, SelectionChangedEventArgs e)
{
var template = ((CollectionView)sender).ItemTemplate;
var frame = (CollectionTemplateView)template.LoadTemplate();
if (frame != null)
{
var theframe = frame.Content;
if (theframe.BackgroundColor is null)
{
MainThread.BeginInvokeOnMainThread(() => theframe.BackgroundColor = Colors.Beige);
}
}
}
If I set a break point on the inner if
, the ClassId
is null. If I set the ClassId
in the ContentView
to be some text, it shows fine (so it is the correct View).
ClassId
is a bindable property, so I’m not sure if I’ve uncovered a bug here in MAUI.
Oddly, setting the background colour also has no effect on the Frame
either. Am I missing something here?