ListView的RowHeight属性不适用于UWP项目

时间:2016-03-21 16:41:29

标签: listview xamarin win-universal-app xamarin.forms

我有ListView设置行高。这适用于iOS和Android,但不适用于UWP。这里行的高度非常小。它与TextCell的默认字体大小一样大。我用这段代码制作了另一个小样本项目:

Title = "Page";
var listView = new ListView
{
    RowHeight = 44,
};
listView.ItemsSource = new string[]
{
    "Test1",
    "Test2",
    "Test3",
    "Test4",
    "Test5",
};

Content = listView;

此代码在示例项目中运行良好,但在大型主项目中没有。

有人知道为什么RowHeight无法在这里工作吗?

2 个答案:

答案 0 :(得分:0)

似乎这是Xamarin.Forms 2.1.0中的一个错误。希望这很快得到修复。

答案 1 :(得分:0)

这适用于xLabs转发器,当然它也适用于您的列表视图?

我在ViewCell上使用ChildAdded Event Property并在代码隐藏上对其进行格式化....嘿......它有效!

                  <!--Users added go here-->              
      <xLabs:RepeaterView x:TypeArguments="models:User" x:Name="UsersAddedStack" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" 
                          ItemsSource="{Binding UsersAdded}" ItemClickCommand="{Binding AddedUserIconClicked}" Spacing="4">

        <xLabs:RepeaterView.ItemTemplate>
          <DataTemplate>                    
            <ViewCell ChildAdded="RepeaterChild_OnChildAdded"><!-- <====fixes height -->
              <Frame Padding="0,6,0,6" OutlineColor="Transparent" HasShadow="False" BackgroundColor="White">
                <Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="White">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="8*"/>
                  </Grid.ColumnDefinitions>
                  <Image Grid.Column="0" Source="user256blue.png" Aspect="AspectFit" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
                  <StackLayout Grid.Column="1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                    <!--First Name + Last Name-->
                    <Label Text="{Binding FullName}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Start"
                         BackgroundColor="White" FontSize="Medium" TextColor="Black"/>
                    <!--Username-->
                    <Label Text="{Binding Username}" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Start"
                         BackgroundColor="White" FontSize="Medium" TextColor="Black"/>
                  </StackLayout>
                </Grid>
              </Frame>
            </ViewCell>
          </DataTemplate>                  
        </xLabs:RepeaterView.ItemTemplate>


      </xLabs:RepeaterView>
private void RepeaterChild_OnChildAdded(object sender, ElementEventArgs e)
{
    var viewCell = sender as ViewCell;
    viewCell.View.HeightRequest = _ccfvm.IconHeight; //_ccfvm is my viewmodel for the page
}