【发布时间】:2020-03-02 18:51:29
【问题描述】:
请帮帮我。在 Xamarin.Forms 我有一个包含卡片的主 ListView(带网格的框架)。每个网格都有标签和带有电话的 ListVew。带有电话的 ListVew 占用三行三列。我需要 Grid 内手机 ListView 的所有元素始终可见(通常它们的数量最多为三个,但可能更多),并且如果需要,Grid 单元格的高度将增加以容纳手机 ViewList 的所有元素.这可能吗?现在网格单元格在标签中的文本高度增加,但在 PhoneListView 高度中没有增加。
[MyListView MainView = new MyListView
{
SeparatorVisibility = SeparatorVisibility.None,
HasUnevenRows = true,
ItemTemplate = new DataTemplate(() =>
{
Grid MyGrid = new Grid
{
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(0.02, GridUnitType.Absolute) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(0.02, GridUnitType.Absolute) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(0.02, GridUnitType.Absolute) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
}
};
...
ListView phonesList = new ListView
{
VerticalScrollBarVisibility = ScrollBarVisibility.Never,
BackgroundColor = Color.Transparent,
SeparatorVisibility = SeparatorVisibility.None,
HasUnevenRows = true,
VerticalOptions = LayoutOptions.FillAndExpand,
ItemTemplate = new DataTemplate(() =>
{
Image phoneButton = new Image { Source = "phone_green.png", HeightRequest = 40, VerticalOptions = LayoutOptions.Center };
Label phoneTextLabel = new Label { HeightRequest = 40, VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center };
phoneTextLabel.SetBinding(Label.TextProperty, "phone");
return new ViewCell { View = new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = { phoneButton, phoneTextLabel } } };
})
};
phonesList.SetBinding(ListView.ItemsSourceProperty, "phones", BindingMode.Default, new PhoneSepConverter());
...
DetailGrid.Children.Add(phonesList, 4, 2);
...
Grid.SetColumnSpan(phonesList, 3);
Grid.SetRowSpan(phonesList, 3);
...
Frame ListItem = new Frame { Content = MyGrid };
return new ViewCell
{
View = ListItem
};
})
};][1]
【问题讨论】:
-
这里是截图链接ibb.co/TRhGZtP
-
你的意思是让所有的 ListItem 一开始就可见吗?不需要滚动?
-
是的。无需滚动。
-
那你为什么不使用 StackLayout 和 BindableLayout 而不是 ListView?
-
不知道BindableLayout,我试试,谢谢
标签: listview xamarin.forms grid