【问题标题】:Cell height not getting set in list view未在列表视图中设置单元格高度
【发布时间】:2017-08-04 15:43:46
【问题描述】:

我在 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
                    };
                })

【问题讨论】:

    标签: c# xamarin xamarin.forms cell


    【解决方案1】:

    我看不到 ListView 是如何定义的。有时间

    listview.HasUnevenRows = true;
    

    帮助

    HasUnevenRows

    【讨论】:

    • 这正是我所需要的。我的行都太大了,但需要该属性来满足行高请求。谢谢
    【解决方案2】:

    我遇到了将多行标签放置在水平方向的 StackLayout 中的奇怪行为。

    请在 Xamarin Forms 论坛中查看 my comment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2018-04-29
      • 2016-10-20
      相关资源
      最近更新 更多