【问题标题】:How to set ListView Row Height in Xamarin.Forms如何在 Xamarin.Forms 中设置 ListView 行高
【发布时间】:2014-11-10 07:42:25
【问题描述】:

我想使用下面提到的代码和绑定在 iOS 设备的 XAML 文件中设置 ListView 的高度。

  1. 我使用 observable 集合来通知属性值何时更新,它会收到通知并设置正确的值,但它没有反映在 iOS 模拟器或设备中,但适用于 Android 和 Windows Phone 设备。
<ListView  Grid.Row="2" Grid.Column="1"  ItemsSource="{Binding QuestionAnswerList,Mode=TwoWay}"  SelectedItem="{Binding SelectedData,Mode=TwoWay}"                   
        HasUnevenRows="true" 
        RowHeight="{Binding Custom_height,Mode=TwoWay}"  
        BackgroundColor="Silver" 
        HorizontalOptions="FillAndExpand" 
        VerticalOptions="FillAndExpand">
        <ListView.ItemTemplate>
  1. 我也尝试静态设置列表视图的行高,但这也不起作用。

  2. 我没有给出任何高度并设置了 Grid RowDefinition height = "*" 但它也没有设置 ListView 的高度,而是与下一个 ListView 行的细节重叠。

谢谢。

【问题讨论】:

    标签: ios iphone ipad xamarin xamarin.forms


    【解决方案1】:

    iOS 上,当您将ListView.HasUnevenRows 设置为true 时,您还必须为每个单元格设置Cell.Height 属性,因为渲染器无法从内容。

    您也可以像在示例中那样使用ListView.RowHeight,用于偶数行。在这种情况下,不要设置ListView.HasUnevenRows(或设置为false)。

    【讨论】:

      【解决方案2】:

      尝试使用 StackLayout 而不是 ListView:

      <StackLayout BindableLayout.ItemsSource="{Binding Items}">
          <BindableLayout.ItemTemplate>
              <DataTemplate>
                  <StackLayout Margin="0,0,0,5">
                      <Label Text="{Binding Name}"/>
                  </StackLayout>
              </DataTemplate>
          </BindableLayout.ItemTemplate>
      </StackLayout>
      

      【讨论】:

      • 我花了几天的时间寻找这个。一种制作列表的方法,而不会被烦人的默认系统列表卡住。非常感谢。
      猜你喜欢
      • 2014-08-21
      • 2012-05-09
      • 1970-01-01
      • 2010-11-17
      • 2016-09-20
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多