Используйте простой StackLayout с BindableLayout, так как вам не нужен прокручиваемый вид.
Поскольку ItemSizingStrategy
недоступно в ListView, все элементы отображаются одинаковым размером первого элемента. Что не подошло бы вашему делу.
Используйте CollectionView
вместо ListView
для mainListView
и установите ItemSizingStrategy
на MeasureAllItems
.
CollectionView mainListView = new CollectionView();
mainListView.ItemsSource = new List<Item>()
{
new Item(){Name = "First", Phones = new List<string>(){ "Pnone 1",} },
new Item(){Name = "Second", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 4"} },
new Item(){Name = "Third", Phones = new List<string>(){ "Pnone 1", "Phone 4"} },
new Item(){Name = "Fourth", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 3", "Phone 4"} },
new Item(){Name = "Fifth", Phones = new List<string>(){ "Pnone 1", "Phone 2"} },
new Item(){Name = "Sixth", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 3"} },
new Item(){Name = "Seventh", Phones = new List<string>(){ "Phone 4"} },
new Item(){Name = "Eight", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 3", "Phone 4"} },
new Item(){Name = "Ninth", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 4"} },
new Item(){Name = "Tenth", Phones = new List<string>(){ "Pnone 1", "Phone 4"} },
new Item(){Name = "Eleventh", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 3", "Phone 4"} },
new Item(){Name = "Tweleth", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 3"} },
new Item(){Name = "Thirteenth", Phones = new List<string>(){ "Pnone 1", "Phone 2", "Phone 3", "Phone 4"} },
new Item(){Name = "Fourteenth", Phones = new List<string>(){ "Pnone 1", "Phone 2"} },
};
mainListView.ItemSizingStrategy = ItemSizingStrategy.MeasureAllItems;
mainListView.ItemTemplate = new DataTemplate(() =>
{
Frame frame = new Frame()
{
CornerRadius = 0,
BackgroundColor = Color.Gray
};
Grid mainItemGrid = new Grid()
{
ColumnDefinitions =
{
new ColumnDefinition(){Width = new GridLength(1, GridUnitType.Star)}
}
};
StackLayout stackLayout = new StackLayout()
{
Orientation = StackOrientation.Vertical
};
stackLayout.SetBinding(BindableLayout.ItemsSourceProperty, "Phones");
BindableLayout.SetItemTemplate(stackLayout, new DataTemplate(() => {
Label label = new Label();
label.SetBinding(Label.TextProperty, ".");
return label;
}));
mainItemGrid.Children.Add(
new Label() { Text = "Some text" }
, 0, 0);
mainItemGrid.Children.Add(
stackLayout, 1, 0);
frame.Padding = 1;
frame.Content = mainItemGrid;
mainItemGrid.BackgroundColor = Color.White;
return frame;
});
Результат пользовательского интерфейса
Пожалуйста, проверьте, поможет ли это вам ...