Description
Description
Hello,
In MAUI, Layout.Children
returns IList<IView>
In Xamarin, Layout.Children
returned IList<View>
Unfortunately, the IView
interface does not expose the vital View
-related property BindingContext
, where the View
class does.
Therefore, in Xamarin.Forms, we could eg. execute such code with ease:
View view = MyStackLayout.Children.FirstOrDefault(c => c.BindingContext == MyViewModel);
Where in .NET MAUI we have to do small hack:
View view = MyStackLayout.Children.Cast<View>().FirstOrDefault(c => c.BindingContext == MyViewModel);
This adds an additional overhead needed for casting and complicates the code. This implies even more hacks when working with indices of Children
property.
In Xamarin.Forms, we could do this for instance:
someList.Add(MyStackLayout.Children[i].BindingContext as MyViewModel);
Where in .NET MAUI we have to do multiple castings this time around, adding even more overhead to the processing:
someList.Add(MyStackLayout.Children.Cast<View>().ToArray()[i].BindingContext as MyViewModel);
Please either:
- add
BindingContext
property to IView interface OR - change signature of
Layout.Children
back to what Xamarin.Forms had -IList<View>
instead ofIList<IView>
Public API Changes
- add
BindingContext
property to IView interface OR - change signature of
Layout.Children
back to what Xamarin.Forms had -IList<View>
instead ofIList<IView>
View view = MyStackLayout.Children.FirstOrDefault(c => c.BindingContext == MyViewModel);
someList.Add(MyStackLayout.Children[i].BindingContext as MyViewModel);
Intended Use-Case
Easier API to work with BindingContext
that does not require hacky Cast<View>
in order to access BindingContext
from Layout.Children
elements.
This is for both performance and ease of use.