【问题标题】:How to autosize the height of a list view in XAML如何在 XAML 中自动调整列表视图的高度
【发布时间】:2017-06-23 18:39:04
【问题描述】:

我的列表视图对象收到一张图片、一个 ID 号和一个概要。概要的大小各不相同,因为有些有空格返回。我注意到 ListView 有一个可以设置的行高(我现在设置为 250),但它只能是一个固定值。那么会发生什么,我的网格对于 ListView 来说变得太大了,导致它溢出并覆盖到下一个列出的项目上。无论如何,是否可以在 XAML 中自动调整列表视图的大小?

<ListView ItemsSource="{Binding List}" VerticalOptions="FillAndExpand" RowHeight="250" SelectedItem="SelectedCTR" SeparatorVisibility="None">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Image Grid.Row="0" HeightRequest="100" MinimumWidthRequest="160" WidthRequest="160" Source="{Binding AttachedmentData,Converter={StaticResource stringToImage}}" />
                    <StackLayout Grid.Row="1" VerticalOptions="FillAndExpand">
                        <Label Text="{Binding Number}" Font="19"
                             TextColor="#f35e20" />
                        <Label Text="{Binding TrimmedSynopsis}" Font="17"
                             TextColor="#503026" />
                    </StackLayout>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

【问题讨论】:

  • 这是什么技术? Xamarin?
  • 你试过不设置高度吗?在 Windows 上的 XAML 中,它会像开箱即用一样工作。
  • 是的,列表视图的默认固定高度非常小,这使得情况变得更糟,因为有很多溢出。
  • 是的,我在 Visual Studio 中使用 Xamarin

标签: c# ios visual-studio xaml xamarin


【解决方案1】:

您需要将HasUnevenRows 添加到True,然后取消设置RowHeight 属性。

<ListView ItemsSource="{Binding List}" VerticalOptions="FillAndExpand" HasUnevenRows="True" SelectedItem="SelectedCTR" SeparatorVisibility="None">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Image Grid.Row="0" HeightRequest="100" MinimumWidthRequest="160" WidthRequest="160" Source="{Binding AttachedmentData,Converter={StaticResource stringToImage}}" />
                    <StackLayout Grid.Row="1" VerticalOptions="FillAndExpand">
                        <Label Text="{Binding Number}" Font="19"
                             TextColor="#f35e20" />
                        <Label Text="{Binding TrimmedSynopsis}" Font="17"
                             TextColor="#503026" />
                    </StackLayout>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

【讨论】:

  • 成功了!谢谢!
【解决方案2】:

只设置ListView属性HasUnevenRows="True"

【讨论】:

    【解决方案3】:

    当你使用Syncfusion Listview 时比

    AutoFitMode="DynamicHeight"  VerticalOptions="FillAndExpand"
    

    属性工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      相关资源
      最近更新 更多