单元格高度未在列表视图中设置

时间:2017-03-14 10:40:53

标签: c# xamarin xamarin.forms cell

我在Xamarin表单应用程序中有一个列表视图,我的一个标签可以有一个很长的文本集。问题是文本被切断,标签的高度永远不会是多行。

我可以制作多线吗? 我可以让身高更高吗?

以下是我的代码。我尝试在几个地方调整高度,但没有一个能让细胞变大。

                //      each item; it must return a Cell derivative.)
                ItemTemplate = new DataTemplate(() =>
                {
                    // Create views with bindings for displaying each property.
                    Xamarin.Forms.Label nameLabel = new Xamarin.Forms.Label();
                    nameLabel.SetBinding(Xamarin.Forms.Label.TextProperty,
                        new Binding("Name", BindingMode.OneWay,
                        null, null, "{0}"));

                    Xamarin.Forms.Label yearLabel = new Xamarin.Forms.Label();
                    yearLabel.SetBinding(Xamarin.Forms.Label.TextProperty,
                        new Binding("Birthday", BindingMode.OneWay,
                            null, null, "FMI {0:yyyy}"));

                    Xamarin.Forms.Label componentLabel = new Xamarin.Forms.Label();
                    componentLabel.SetBinding(Xamarin.Forms.Label.TextProperty,
                        new Binding("Component", BindingMode.OneWay,
                            null, null, "Component: {0}"));

                    Xamarin.Forms.Label descriptionLabel = new Xamarin.Forms.Label();
                    descriptionLabel.SetBinding(Xamarin.Forms.Label.TextProperty,
                        new Binding("Description", BindingMode.OneWay,
                            null, null, "{0}"));
                    descriptionLabel.HorizontalOptions = LayoutOptions.FillAndExpand;

                    descriptionLabel.LineBreakMode = LineBreakMode.NoWrap;
                    descriptionLabel.HeightRequest = 256.0;
                    descriptionLabel.MinimumHeightRequest = 250.0;

                    BoxView boxView = new BoxView();
                    boxView.SetBinding(BoxView.ColorProperty, "SeverityColor");
                    boxView.MinimumHeightRequest = 100.0;
                    boxView.MinimumHeightRequest = 100.0;

                    // Return an assembled ViewCell.
                    return new ViewCell
                    {
                        View = new StackLayout
                        {
                            Padding = new Thickness(0, 2),
                            Orientation = StackOrientation.Horizontal,
                            HeightRequest = 155.0,
                            MinimumHeightRequest = 155.0,
                            Children =
                                {
                                    boxView,
                                    new StackLayout
                                    {
                                        VerticalOptions = LayoutOptions.Center,
                                        HorizontalOptions = LayoutOptions.Fill,
                                        Spacing = 0,
                                        HeightRequest = 235.0,
                                        MinimumHeightRequest = 250.0,

                                        Children =
                                        {
                                            componentLabel,
                                            descriptionLabel
                                        }
                                   }
                                }
                        },Height = 250
                    };
                })

2 个答案:

答案 0 :(得分:2)

我没看到如何定义ListView。

listview.HasUnevenRows = true;

帮助

HasUnevenRows

答案 1 :(得分:0)

我遇到了多行标签的奇怪行为,这些标签放置在具有水平方向的StackLayout中。

请参阅Xamarin Forms论坛中的my comment