在Windows 8.1 GridView中不显示具有Visibility = Collaped的项目 [英] Not showing items with Visibility=Collapsed in Windows 8.1 GridView

查看:26
本文介绍了在Windows 8.1 GridView中不显示具有Visibility = Collaped的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows 8.1应用程序,其中的 GridView 绑定到自定义(可排序,重复数据删除)的可观察集合.在此集合中,我进行了一些繁重的筛选,并为每个项目设置了一个IsHidden标志.

I have a Windows 8.1 application with a GridView bound to a custom (sortable, deduplicated) observable collection. In this collection, I do some heavy filtering and setting an IsHidden flag for every item.

在该项目的数据模板中,如果IsHidden标志设置为true,则存在使该项目折叠的条件.

In the data template for the item, there is a condition making the item collapsed if IsHidden flag is set to true.

<Grid Width="160" Height="280" Visibility="{Binding IsHidden, Converter={StaticResource InvertedBooleanToVisibilityConverter}}">

此方法在Windows Phone 8.1 XAML中有效,使项目从 ListView 中消失,但在Windows 8.1 GridView 中不起作用.Windows 8.1的问题在于,当我将集合中的一个项目设置为隐藏时,id从 GridView 消失了,但留下了一个空的地方,因此 GridView .

This approach works in Windows Phone 8.1 XAML, making the items disappear from the ListView but it does not work in Windows 8.1 GridView. The problem with Windows 8.1 is that when I set an item in the collection to hidden, id disappears from the GridView but leaves an empty place, so there is a gap in the GridView.

关于如何解决它的任何想法?也许是相同的XAML样式编辑?

Any ideas on how to solve it? Maybe same XAML style editing?

这里是重现此问题的最小解决方案: https://dl.dropboxusercontent.com/u/73642/gv.zip

Here is a minimal solution to reproduce the problem: https://dl.dropboxusercontent.com/u/73642/gv.zip

我尝试将项目的宽度和高度绑定到hidden标记,并在项目被隐藏时将其设置为0,但这并没有帮助,在 GridView 中仍然存在间隙.

I tried binding width and height of the items to the hidden flag and setting it to 0 when the item is hidden, but it did not help, still a gap in the GridView.

更新:一种解决方法是过滤实际的绑定集合,但是由于某些业务需求,这是不可能的.

Update: One workaround would be filtering the actual bound collection, but this is not possible, because of some business requirements.

推荐答案

问题出在 GridView ItemsPanel 中.

ItemsWrapGrid WrapGrid 都是统一的网格.他们所有的子元素将共享相同的高度和宽度.这就是即使折叠 ItemTemplate 仍保留该空间的原因.

Both ItemsWrapGrid and WrapGrid are uniform grids. All their child elements will be sharing the same height and width. That's why even if you collapse the ItemTemplate, the space is still reserved.

这里真正需要的是一个 WrapPanel .WINRT没有内置的 WrapPanel ,但是Jerry Nixon已经构建了一个,您可以从这里.

What you really need here is a WrapPanel. WINRT doesn't have a built-in WrapPanel but Jerry Nixon has built one and you can grab it from here.

更新 GridView ItemsPanel 之后,您还有另一件事要做.您还需要获取承载 Itemtemplate GridViewItem ,并将其 Visibility 设置为 Collapsed .

After you updated your GridViews ItemsPanel, you still have one more thing to do. You need to also get the GridViewItem that hosts your Itemtemplate and set its Visibility to Collapsed.

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        ds[5].IsHidden = true;
  
        await Task.Delay(1000);
        var gridViewItem =(GridViewItem)this.gv.ContainerFromIndex(5);
        gridViewItem.Visibility = Visibility.Collapsed;
    }

我在上面稍加延迟,以使崩溃更明显.

I put a little delay above to make the collapsing more obvious.

这篇关于在Windows 8.1 GridView中不显示具有Visibility = Collaped的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆