Open bakerhillpins opened 2 years ago
Same as #15051 could you validate that this still happens in the latest stable version? Thanks!
Same as #15051 could you validate that this still happens in the latest stable version? Thanks!
Yes, it's in the latest code. Sorry for not putting that in there. I should have just updated the Forms Example code that I used to repo it but I didn't, I've been building the tip of the 5.0 branch to look at what's going on. There are several places in the code where this is going to be an issue. Lots of places that bind to DataTemplates.
@jfversluis 2 important points:
Whoops sorry about that! It's coming up on the end of the day/week here, losing focus 😅
Thanks for the (quick) response! If you are actually building the source and are willing and able to maybe fix it yourself I think that could greatly increase your chances and the speed of this being resolved and included.
We're doing the best we can right now, but there is still a lot to do, so if there is anything you could offer in that regard it would be greatly appreciated.
Whoops sorry about that! It's coming up on the end of the day/week here, losing focus 😅
No worries.. I've been there myself.
If you are actually building the source and are willing and able to maybe fix it yourself I think that could greatly increase your chances and the speed of this being resolved and included.
I'm looking into that as I'd really like to see this fixed but as I mentioned this is bigger than CollectionView. Learning curve is steep too.
We're doing the best we can right now, but there is still a lot to do, so if there is anything you could offer in that regard it would be greatly appreciated.
Totally understand. I'm eager for all of this and well aware of your situation, it seems to be SOP for all of us these days.
As a work around you can return
new DataTemplate(typeof(ContentView));
which seems to not render the item at all :)
@JackDevAU Yes, that avoids the exception, but as you noticed it displays nothing, and for several controls it's actually supplying the wrong type of View container. As I worked through the PR I noted that the default template is dependent upon both the control and in a few cases the platform as well.
With a little experimentation you could come up with a proper default for each circumstance, such as a Label where the Text Property is bound to the BindingContext and is wrapped in the proper View container. Which should result in presenting the type of the object assigned to the BindingContext as a string, so you'd see something.
Description
Returning null from
DataTemplateSelector.OnSelectTemplate(object item, BindableObject container)
results inNullReferenceException
s. The Xamarin documentation from MS isn't clear on this being valid or not, However, the WPF documentation is clear that null is a valid return value.The Xamarin Example docs don't list a null return as a limitation either.
I've always returned null as a default case for desktop apps, and I am surprised this is throwing in Xamarin. It seems reasonable that null would be valid, since the absence of a DataTemplate definition for various
ItemTemplate
properties works without incident.Steps to Reproduce
Expected Behavior
Returning null from
DataTemplateSelector.OnSelectTemplate(object item, BindableObject container)
should result in the item being displayed in the default manner, as if theItemTemplate
property wasn't set at all.Actual Behavior
See lines 13/14 in
CollectionViewDemos\Controls\MonkeyDataTemplateSelector.cs
NullReferenceExceptions from a variety of different places. This particular example throws here:
Basic Information
Reproduction Link
CollectionViewDemos.zip
Workaround
See this comment for a possible workaround.