Not showing items with Visibility=Collapsed in Windows 8.1 GridView

前端 未结 3 685
旧时难觅i
旧时难觅i 2021-01-11 19:32

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

3条回答
  •  轮回少年
    2021-01-11 19:46

    The problem is in the GridView's ItemsPanel.

    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.

    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.

    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.

提交回复
热议问题