This question already has an answer here:
Xamarin Binding property not found (1 answer)
Closed 20 days ago.
I am trying to set my items to appear on a ListView but when I run the app the listview displays "Name" with the number of objects contained in the JSON file but it displays in the console log
"Binding: 'taskName' property not found on 'LastSince.TasksClass', target property: 'Xamarin.Forms.Label.Text'" I am not sure why but my class and listview setup are below:
<ListView BackgroundColor="#686d7e"
Margin="0,0,0,0"
HeightRequest="350"
x:Name="sinceItemsListView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="Name"></Label>
<Label Text="{Binding taskName}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
And the C# class is:
public string taskName;
public string taskDescription;
public string taskPriority;
public TasksClass(string taskName, string taskDescription, string taskPriority)
{
this.taskName = taskName;
this.taskDescription = taskDescription;
this.taskPriority = taskPriority;
}
and finally, the code to apply the listview is:
ObservableCollection<TasksClass> tasksList { get; set; }
fileHandler fileHandler = new();
public string loadedJson;
public Tasks()
{
InitializeComponent();
tasksList = new ObservableCollection<TasksClass>();
sinceItemsListView.ItemsSource = tasksList;
}
protected override void OnAppearing()
{
base.OnAppearing();
DeseraliseJSON();
sinceItemsListView.ItemsSource = tasksList;
}
I am not sure why this is wrong; I can only assume the binding isn't setup correctly but appreciate any help.
I tried running a listview of items but returns empty values because the binding property cannot be found
1条答案
按热度按时间rfbsl7qr1#
请尝试替换视图模型中的属性
taskName
,如下所示:与