我正在嘗試使用 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 頁面可以找到計劃 ObservableCollection 本身,但不能找到應該在串列中的屬性,如“fromICAO”和“toICAO”。資料模板中的標簽也只能找到計劃,而不能找到其中的屬性。我究竟做錯了什么?
uj5u.com熱心網友回復:
通過使用Essentials 主執行緒強制資料更新它作業,我可以解決屬性。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/351312.html
標籤:C# xml 沙马林 xamarin.forms
上一篇:問題新行不會創建和替換第一行
下一篇:我無法在C 中將引數傳遞給我的類
