我有一個問題,要在另一個串列中實作串列,我有一個專案的串列,每個專案都有尺寸、數量和價格的串列。用戶選擇尺寸并輸入數量,然后選擇父項,如何在xamarin表單中實作這個功能?
uj5u.com熱心網友回復:
你可以嘗試使用一個帶有嵌套CollectionView或ListView的Bindable Layout,這將允許你使用List of Lists來系結資料。
它可以是這樣的;
C#
public class MyNestedListItem {
public MyNestedListItem(string myTest) {
MyText = myText。
}
public string MyText { get; set; }
}
public class MyList {
public MyList(string listName, list<MyNestedListItem>/span> myNestedList) {
ListName = listName;
MyNestedList = myNestedList;
}
public string ListName { get; set; }
public List<MyNestedListItem> MyNestedList { get; set; }
}
public class MyViewModel {
public ObservableCollection<MyList>/span> MyList { get; set }
public MyViewModel() {
var nestedListA = new List<MyNestedListItem>/span>
{
new MyNestedListItem("A1")。
new MyNestedListItem("A2");
new MyNestedListItem("A3");
}
var nestedListB = new .....;
MyList = new ObservableCollection<MyList>/span> {
new MyList("List A", nestedListA);
new MyList("List B", nestedListB);
}
}
XAML
<StackLayout Orientation="Horizontal"/span>
VerticalOptions="Start"
HorizontalOptions="Center"/span>
BindableLayout.ItemsSource="{Binding MyList}"/span>>
<BindableLayout.ItemTemplate>/span>
<DataTemplate>/span>
<Frame WidthRequest="75"/span>
HeightRequest="25"/span>
CornerRadius="25"/span>
Padding="0"/span>
HasShadow="True">>
<Label Text="{Binding ListName }"
<CollectionView ItemsSource="{Binding MyNestedList }"/span>
VerticalOptions="Center"。
HorizontalOptions="Center"/span>>
<CollectionView.ItemTemplate>
<DataTemplate>/span>
<StackLayout>/span>
< ..... 你的布局東西在這里 />
</StackLayout>
</DataTemplate>/span>
</CollectionView>/span>
</Frame>/span>
</DataTemplate>/span>
</BindableLayout.ItemTemplate>
這可能是實作嵌套串列的一個好的起點
uj5u.com熱心網友回復:
你可以在listview里面使用一個兩行四列的Grid來避免嵌套串列
。它可以更容易地實作你的頁面風格。
檢查這個鏈接(
)。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/312687.html
標籤:


