Home > database >  Binding property "fromICAO" not found on "ViewModel" in collectionview
Binding property "fromICAO" not found on "ViewModel" in collectionview

Time:11-07

I am trying to show data using a collection view in Xamarin but the Binding for the text in one of the labels cannot find the property in the viewmodel

my view:

<CollectionView x:Name="ItemsCollectionView"
                                 ItemsSource="{Binding Plans}"
                                 SelectionMode="None">
                     <CollectionView.ItemTemplate>
                         <DataTemplate>
                             <Frame HasShadow="True">
                                 <StackLayout>
                                     <Grid>
                                         <Grid.RowDefinitions>
                                             <RowDefinition Height="60"/>
                                         </Grid.RowDefinitions>
                                         <Grid.ColumnDefinitions>
                                             <ColumnDefinition/>
                                             <ColumnDefinition/>
                                         </Grid.ColumnDefinitions>
                                         <StackLayout Spacing="0">
                                             <Label Text="From:" 
                                                    FontSize="10"
                                                    TextColor="Black"></Label>
                                             <Label Text="{Binding fromICAO}" 
                                                    FontSize="24"
                                                    TextColor="Black"></Label>
                                             <Label Text="To:" 
                                                    FontSize="10"
                                                    TextColor="Black"></Label>
                                             <Label Text="{Binding toICAO}" 
                                                    FontSize="24"
                                                    TextColor="Black"></Label>
                                         </StackLayout>
                                         <StackLayout  Spacing="0"
                                                       Grid.Column="1">
                                             <Label Text="Distance:" 
                                                    FontSize="10"
                                                    TextColor="Black"></Label>
                                             <Label Text="{Binding distance}" 
                                                    FontSize="24"
                                                    TextColor="Black"></Label>
                                             <Label Text="Fuel used:" 
                                                    FontSize="10"
                                                    TextColor="Black"></Label>
                                             <Label Text="{Binding fuelUsed}" 
                                                    FontSize="24"
                                                    TextColor="Black"></Label>
                                         </StackLayout>
                                     </Grid>
                                 </StackLayout>
                             </Frame>
                         </DataTemplate>
                     </CollectionView.ItemTemplate>
                 </CollectionView>

my viewmodel:

public ObservableCollection<PlanToFirestoreModel> Plans { get; set; }
    
         public PlansViewModel() {
             firestoreService = DependencyService.Get<IFirestoreService>();
             auth = DependencyService.Get<IFirebaseAuthentication>();
             Plans = new ObservableCollection<PlanToFirestoreModel>();
    
             FillData();
         }
    
         public async void FillData()
         {
             var tempPlans = await firestoreService.GetFlightPlansByUid(auth.GetUserInfoAsync().Id);
             foreach (var plan in tempPlans)
             {
                 Plans.Add(plan);
             }
         }

and my Model itself:

public class PlanToFirestoreModel : BasePlanModel
     {
         public string fromICAO { get; set; }
         public string toICAO { get; set; }
         public string fromName { get; set; }
         public string toName { get; set; }
         public int id { get; set; }
         public string userId { get; set; }
         public string aircraft { get; set; }
         public string deptCountry { get; set; }
         public string arrCountry { get; set; }
         public double fuelUsed { get; set; }
         public string flightNumber { get; set; }
         public double distance { get; set; }
         public string altitude { get; set; }
         public string createdAt { get; set; }
         public double deptLon { get; set; }
         public double deptLat { get; set; }
         public double arrLon { get; set; }
         public double arrLat { get; set; }
     }

The XAML page can find the Plans ObservableCollection itself but not the properties that are supposed to be in the list like "fromICAO" and "toICAO" The label within the datatemplate can also only find Plans but not the properties within. What am I doing wrong?

CodePudding user response:

by using Essentials Mainthread to force data to update it worked and I could address the properties.

  • Related