【发布时间】:2020-04-19 17:33:58
【问题描述】:
我在 Xamarin.Forms 中有一个包含 2 个标签的列表视图和另一个列表视图。 为 Android 和 iOS 构建。
这是特定的代码
listView.ItemTemplate = new DataTemplate(() => {
var grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
Label l = new Label() { };
l.SetBinding(Label.TextProperty, new Binding("TeachersName"));
grid.Children.Add(l);
Label l2 = new Label() { };
l2.SetBinding(Label.TextProperty, new Binding("TeachersEmail"));
grid.Children.Add(l2);
Grid.SetRow(l, 1);
Grid.SetRow(l2, 2);
SfListView embeddedView = new SfListView();
embeddedView.AutoFitMode = AutoFitMode.Height;
embeddedView.LayoutManager = new GridLayout();
//embeddedView.SelectionMode = Syncfusion.ListView.XForms.SelectionMode.None;
embeddedView.LayoutManager.SetBinding(GridLayout.SpanCountProperty, new Binding("NoOfCat"));
embeddedView.SetBinding(SfListView.ItemsSourceProperty, new Binding("CatInfoSet"));
embeddedView.ItemTemplate = new DataTemplate(() => {
var MainGrid = new Grid() { VerticalOptions = LayoutOptions.StartAndExpand};
Grid Holder = new Grid() {Padding = new Thickness(5) };
SfCircularProgressBar circularProgressBar = new SfCircularProgressBar() {Margin = new Thickness(5)};
circularProgressBar.SetBinding(ProgressBarBase.ProgressProperty, new Binding("Percent"));
Holder.Children.Add(circularProgressBar);
Label label = new Label() { HorizontalOptions = LayoutOptions.Center };
label.SetBinding(Label.TextProperty, new Binding("Description"));
MainGrid.Children.Add(Holder);
MainGrid.Children.Add(label);
return MainGrid;
});
grid.Children.Add(embeddedView);
Grid.SetRow(embeddedView, 0);
return grid;
});
我感觉它类似于导致问题的行定义,但似乎无法弄清楚。
更新:如果我重新排列网格项目,将标签放在进度条之前,它们就会显示出来......这真的很奇怪
【问题讨论】:
-
哪个标签在 Android 中不可见?将 listView 放在另一个 listview 中从来都不是一个好的设计。
-
您将
RowDefinitions的高度全部设置为auto,而listView在row 0中,它会自动占用所有空间,然后标签不会出现。尝试为第 0 行指定一个绝对高度,例如 100,您将在 listView 下看到这些标签。 -
@JackHua-MSFT 是的,我知道,但我想不出其他方法。
-
@JackHua-MSFT 哦,非常感谢!
-
您能否接受答案,以便我们可以帮助更多有相同问题的人:)?
标签: c# android ios listview xamarin.forms