我試圖讓Xamarin窗體在列表中顯示一個列表。我見過其他人說不支持嵌套在ListView中的ListView。我試圖在ListView中添加一個控件,並將嵌套列表綁定到控件,但是每當我嘗試綁定它時,總會崩潰我的應用程序。我也發現有人建議使用分組。將DOES分組工作,但是我發現的問題是我無法點擊分組部分。此外,分組不會實時更新(這是一項要求)。如何顯示Xamarin表單中的項目的嵌套列表?
對於最終的結果,我想是這樣簡單的事情:
- ApartmentName1
- 地址
- 經理電話號碼
- 租戶1,電話號碼
- 租客2,電話號碼
- 租戶3,電話號碼
- ApartmentName2
- 地址
- 經理電話號碼
- 租戶1,電話號碼
- 租客2,電話號碼
- 租戶3,電話號碼
下面是一個例子對象,我想在我的Xamarin窗體項目中顯示。
public class Apartment
{
public string ApartmentName { get; set; }
public string Address { get; set; }
public string ManagerPhoneNumber { get; set; }
public List<Tenant> Tenants { get; set; }
}
public class Tenant
{
public string FullName { get; set; }
public string PhoneNumber { get; set; }
public DateTime ContractExpireDate { get; set; }
}
這裏是XAML中我試圖去上班
<ContentView>
<StackLayout>
<ListView x:Name="apartmentListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout VerticalOptions="StartAndExpand">
<StackLayout Orientation="Horizontal" BackgroundColor="Gray">
<Label HorizontalOptions="StartAndExpand" Text="{Binding ApartmentName}" />
<Label HorizontalOptions="End" Text="{Binding Address}" />
</StackLayout>
<Label Text="{Binding ManagerPhoneNumber}" />
<control:TenantViewTemplate Tenants="{Binding Tenants}" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentView>
我只是想顯示一個列表,其中包含一個列表。對於如何通過Xamarin Forms做到這一點,我願意接受任何建議。
是它的答案或建議嗎? –
我不相信。用XAML編寫用戶界面是最好的方法,如果你抓到一些書會看到建議。 –
閱讀書籍隊友。它不會改變它。最後直到有所見即所得的編輯器XAML沒有優於純代碼的優勢。 1.執行速度較慢。 2.開發沒有調試器和小智能。假設你保持你的代碼清潔,那麼它的代碼就更詳細了。像這樣的情況一直出現,如果OP使用C#開始,這永遠不會是一個問題。 – David