Open omghb opened 1 year ago
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
@StephaneDelcroix thoughts?
public int ListCount => list.Length;
🧐
what would List.Count
return ?
It returns 3. That's the tricky part 😉.
An Array has not a visible Count
property. The visible property is the Length
property.
However, an Array
implements the interfaces ICollection
, ICollection<T>
and IReadOnlyCollection<T>
. All of them declare a property Count
. So the Array
supports the Count
property when used via interface.
We expose Collections often via IReadOnlyList<T>
within a ViewModel and Bind to them. In Xamarin it was possible to Bind to the Count
property. In MAUI it seems that this is not working anymore.
We could rewrite the example also like this:
public int ListCount => List.Count;
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 2.0. Can repro on android and windows platform with above code.
My current tests shows that it actually works with XamlC on (and compiled bindings) like in Release but fails in DEBUG. and it's not beer-o-clock yet
this probably never worked on XF, the difference being that maui disable Xaml compilation on debug builds
It works with XF 5 for a released and published App (in Debug and Release mode).
We run into multiple bugs because of this issue after migration to MAUI. And we had to implement workarounds for those bindings so that the App works with MAUI again.
Bug is still in version 8.0.40
.
The new collection initializer of C# 12 will also not work:
public IReadOnlyList<string> List { get; private set; } = [];
Using {Binding List.Count}
does not work for []
although the interface supports the Count property: IReadOnlyList<T>.Count
.
Description
Compiled Binding to Array.Count provides no result. Building works without any error or warning.
Last version that worked well: Xamarin Forms 5.0.
We run into this issue during migration from Xamarin Forms 5.0 to MAUI 7.0. In Xamarin Forms this worked well.
Steps to Reproduce
MainPage.xaml
with:MainPage.xaml.cs
withpublic partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); BindingContext = new MainViewModel(); } }
public class MainViewModel { private readonly string[] list = new[] { "Bill", "Steve", "John" };
}