Skip to content

Compiled Binding to Array.Count provides no result #13872

@omghb

Description

@omghb

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

  1. Create a new empty MAUI app
  2. Replace content of MainPage.xaml with:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:MauiApp2"
             x:Class="MauiApp2.MainPage" x:DataType="local:MainViewModel">

    <VerticalStackLayout>
        <Label Text="List.Count:"/>
        <Label Text="{Binding List.Count}"/>

        <Label Text="ListCount:"/>
        <Label Text="{Binding ListCount}"/>
    </VerticalStackLayout>
</ContentPage>
  1. Replace MainPage.xaml.cs with
namespace MauiApp2;

public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();
		BindingContext = new MainViewModel();
	}
}

public class MainViewModel
{
    private readonly string[] list = new[] { "Bill", "Steve", "John" };

    public IReadOnlyList<string> List => list;

    public int ListCount => list.Length;
}

Note: You might need to adapt the namespace.

  1. Run application.
  • See that first Binding results in an empty value -> BUG
  • Second Binding results in the value 3 -> correct.

Link to public reproduction project repository

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows

Affected platform versions

All

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Labels

area-xamlXAML, CSS, Triggers, Behaviorsmigration-compatibilityXamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convertplatform/androidplatform/iosplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions