4
votes

I have simple Page with ListView

<ListView x:Name="ForecastView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding mainData.Temperature}" />
        </DataTemplate>
    </ListView.ItemTemplate>
 </ListView>

I'm trying to bind nested property by using . to access it. My item source:

private ObservableCollection<ForecastData> forecast = new ObservableCollection<ForecastData>();

I'm setting it in constructor:

ForecastView.ItemsSource = forecast;

My model is looking like this:

public class ForecastData
    {
        public MainData mainData;
.....
public class MainData
    {
        public double Temperature;
...

After REST call my list is populated by elements (I can select them), but text property is blank. Can You help me figure out what is wrong. I have tried everything and nothing helps (I have read all similar question on Stack Overflow).

1
"Tamarin forms" - devRicher
you can only bind to public properties (with getters and setters) not public variables or methods - Jason

1 Answers

6
votes

The problem is that you are trying to bind to a public field.

You can only bind to properties.

So change:

public MainData mainData;

To:

public MainData mainData { get; set; }

And it should work!

Also for Temperature of course.