【问题标题】:Weird ListView behavior in Universal Windows Apps通用 Windows 应用程序中的奇怪 ListView 行为
【发布时间】:2016-06-21 04:57:30
【问题描述】:

我们的应用程序以前是为 Windows 8.1 设计的。我们现在正在考虑将其移植到适用于 Windows 10 的通用 Windows 应用程序。

我们注意到行为有所不同,特别是 ListView / ItemsControl

  • 折叠的可见性现在正在占用空间。在 Win 8.1 中,折叠的可见性没有多余的空间
  • ListViewItems 的附加边距,特别是如果 ItemsPanel 是水平。似乎总是有大约 10 像素的右边距。

奇怪的是,对于第二个项目符号,将其更改为 GridView 解决了边距问题。不过,第一颗子弹仍然存在。

有没有其他人遇到过这个问题,你是怎么解决的?

谢谢

编辑:参考代码:

<GridView Grid.Row="1"
  ItemsSource="{Binding Path=Tables}">
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
    <Setter Property="VerticalContentAlignment" Value="Top" />
    <Setter Property="Margin" Value="0" />
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemTemplate>
<DataTemplate>
    <Grid Visibility="{Binding Path=ShowTable, Converter={StaticResource BoolToVisConverter}}">
        <!-- A lot of UI Element -->
    </Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
    <ItemsStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>

这是我的代码。我已经对其进行了跟踪,并且网格的可见性工作正常(真/假,正确设置可见性)。问题是,即使“网格”被隐藏,“GridViewItem”似乎仍然会占用空间。 GridViewItem 的宽度似乎没有改变。在 Windows 8.1 应用上,没有空格。

这是一个错误吗?

【问题讨论】:

  • 折叠的项目不应占用空间。请分享一些代码。 ??? ListBiewItem/GridViewItem 默认设置了一些间距。您必须更改 ItemContainerStyle 才能摆脱它。
  • 谢谢凯,我已经提供了代码参考。我确实有 ItemContainerStyle 但它似乎仍然不正确。

标签: xaml listview win-universal-app


【解决方案1】:

GridViewItems 有一个默认的MinWidth 定义。您必须在ItemContainerStyle 中删除它。您可以查看默认模板here

<Setter Property="MinWidth" Value="0" />

我无法重现您的额外保证金问题。使用上面显示的代码,List 中的所有元素都彼此相邻。

【讨论】:

  • 谢谢凯!那行得通!我比较了 Win8 和 Win10 ListViewItem 的默认样式,有很多变化,包括 MinWidth。既然我知道出了什么问题,就需要看看其他人。
猜你喜欢
  • 1970-01-01
  • 2014-09-22
  • 1970-01-01
  • 1970-01-01
  • 2016-03-23
  • 2023-03-03
  • 2016-11-02
  • 2020-02-03
  • 1970-01-01
相关资源
最近更新 更多