Skip to content

XAML Data Binding Error - Object reference not set to an instance of an object. #25819

@kycuff

Description

@kycuff

Description

When trying to bind a label's text to a back end property that has a complex model I am getting this error:

"Object reference not set to an instance of an object."

An example of this can be found in the reproduction repo for the label:

<Label
    HorizontalTextAlignment="Center"
    Style="{DynamicResource TextHeadline}"
    Text="{Binding UsersData.InstalmentPlans.InstalmentPlan[0].FinancialYear}" />

Here is the data model:

public partial class UserDataViewModel : ObservableObject
{
    public UsersDataModel UsersData { get; set; }
    public UserDataViewModel()
    {
        UsersData = new UsersDataModel
        {
            InstalmentPlans = new InstalmentPlans
            {
                InstalmentPlan = new[]
                {
                    new InstalmentPlan { FinancialYear = "2023" }
                }
            }
        };
    }
}

We have successfully used the list index in other places to bind the XAML

Steps to Reproduce

Link to the reproduction link below

Link to public reproduction project repository

https://github.com/kycuff/TestApp.git

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

Create a new field within the code behind file to retrieve UsersData.InstalmentPlans.InstalmentPlan[0].FinancialYear and bind that to the label

Relevant log output

15:57:32:097	2>        Resource: App.Routes.CouncilTax.Pages.Specific.InstalmentsPage.xaml
15:57:32:097	2>          Parsing Xaml
15:57:32:097	2>            done.
15:57:32:097	2>          Replacing 0.InitializeComponent ()
15:57:32:097	2>            failed.
15:57:32:097	2>    Routes\CouncilTax\Pages\Specific\InstalmentsPage.xaml : XamlC error : Object reference not set to an instance of an object.

Metadata

Metadata

Labels

area-xamlXAML, CSS, Triggers, Behaviorsfixed-in-9.0.21platform/androids/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

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions