在 collectionview 的 "ViewModel" 上找不到绑定 属性 "fromICAO"
Binding property "fromICAO" not found on "ViewModel" in collectionview
我正在尝试使用 Xamarin 中的集合视图显示数据,但其中一个标签中文本的绑定无法在视图模型中找到 属性
我的看法:
<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>
我的视图模型:
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);
}
}
和我的模型本身:
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; }
}
XAML 页面可以找到 Plans ObservableCollection 本身,但找不到应该在列表中的属性,如“fromICAO”和“toICAO”
datatemplate 中的标签也只能找到 Plans,而不能找到其中的属性。
我做错了什么?
通过使用 Essentials Mainthread 强制数据更新它起作用了,我可以解决属性问题。
我正在尝试使用 Xamarin 中的集合视图显示数据,但其中一个标签中文本的绑定无法在视图模型中找到 属性
我的看法:
<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>
我的视图模型:
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);
}
}
和我的模型本身:
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; }
}
XAML 页面可以找到 Plans ObservableCollection 本身,但找不到应该在列表中的属性,如“fromICAO”和“toICAO” datatemplate 中的标签也只能找到 Plans,而不能找到其中的属性。 我做错了什么?
通过使用 Essentials Mainthread 强制数据更新它起作用了,我可以解决属性问题。