"From" is a member of UpcomingJobsList model, so you should set the ListView "x:DataType" to UpcomingJobsList model.
Binding question (newbie)
Hi
My UpcomingJobsPage is bound to UpcomingJobsViewModel and has the xaml as below at the end.
The RefreshView is bound to UpcomingJobsViewModel and calls command LoadDataCommand to load data into the ObservableCollection UpcomingJobsList. The listview is bound to UpcomingJobsList. Pretty standard stuff.
My question is how in general can I choose to bind my UpcomingJobsPage view elements to either UpcomingJobsViewModel properties or UpcomingJobsList properties? For instance in below code I need the 'From' to be coming from UpcomingJobsList but it says;
Thanks
Regards
<ContentPage.Content>
<Grid>
<RefreshView x:DataType="viewmodels:UpcomingJobsViewModel" Command="{Binding LoadDataCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
<ListView x:Name="listView" ItemsSource="{Binding UpcomingJobsList}" >
<ListView.ItemTemplate>
<DataTemplate >
<ViewCell>
<ViewCell.View>
<Grid >
<Label Text="{Binding From}" />
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</RefreshView>
</Grid>
</ContentPage.Content>
1 additional answer
Sort by: Most helpful
-
Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,416 Reputation points Microsoft External Staff
2021-06-29T02:04:17.18+00:00 Hello,
Welcome to our Microsoft Q&A platform!As alessandrocaliaro said, you could set the ListView "x:DataType" to UpcomingJobsList model, like the code following:
<DataTemplate x:DataType=" the model you used in UpcomingJobsList">
For more information, you can refer to https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/compiled-bindings
Best Regards,
Wenyan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.