【问题标题】:ListView.HasUnevenRows property is not working in Xamarin.Forms.iOSListView.HasUnevenRows 属性在 Xamarin.Forms.iOS 中不起作用
【发布时间】:2021-12-23 20:51:29
【问题描述】:

如果我设置“ListView.hasUnevenRows = True”,那么列表视图的行高应该基于它的项目内容。这适用于 Android 和 iOS(几乎所有设备)。

但在 iPhone 12 (14.5) 中,此属性不起作用,这意味着行高不是根据项目内容设置的。

以前有人遇到过这种情况吗?我应该在 Xamarin 官方论坛上问这个问题,但在此之前我只想确认是否有任何解决方法,或者我在这里错过了什么

【问题讨论】:

  • 您何时(何地)设置它?您是在 XAML 中设置它,还是在构建它时设置它,还是稍后?显示您正在讨论的确切代码/xml。
  • 是的,我在 XAML 中设置它。作为 ListView 的 ItemTemplate,我添加了以下标签,并且收到了上述错误,
  • 我之前没有看到任何关于此类问题的报告。请将它所在的页面简化为最简单的页面,但仍然存在问题。 然后将整个页面 XAML 添加到您的问题中。还有 .xaml.cs 代码隐藏文件。 (如果您使用最简单的 xamarin 项目创建一个公共存储库会更好,这样可以显示问题。并在 github.com/xamarin/Xamarin.Forms/issues. 添加一个新问题)

标签: c# xamarin xamarin.forms xamarin.forms.listview


【解决方案1】:

我做了一个测试,效果很好,如下所示:

xmal:

<ListView x:Name="mylist" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
  <ViewCell>
      <StackLayout>
          <Label Text="{Binding Name}"/>
      </StackLayout>
  </ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

代码隐藏:

 public TestPage1()
    {
        InitializeComponent();
        List<People> peoples = new List<People> {
            new People {Name="111111111111111111111111111111111111111111111111111222" ,age=10},
            new People{Name="333333333333" ,age=20},
            new People{ Name="hahahahahaha" ,age=30}
        };
        mylist.ItemsSource = peoples;
        
    }

这里有一个示例链接,您可以自己测试: https://github.com/xamarin/xamarin-forms-samples/tree/main/WorkingWithListview/WorkingWithListview/Uneven

【讨论】:

  • 感谢您的回复!在你的情况下,问题没有发生,但在我的情况下,问题来了。用下面的标签代码替换你的标签,你会得到一个问题,
  • @Divaker - 请下载 Adrian 提供的代码。贴上你怀疑会引起麻烦的标签。报告问题是否发生。 (如果不是,那么比较工作项目和不工作项目。开始改变它们,使它们更相似,直到你找出导致它的确切原因。)
  • O 发现使用 ```
猜你喜欢
  • 2021-04-29
  • 2011-02-26
  • 2018-08-23
  • 2015-11-21
  • 2011-11-02
  • 1970-01-01
相关资源
最近更新 更多