How to change the visibility of GridViewItems using property binding?
I cannot create another ObservableCollection to filter out the one I use as ItemsSource . I tried using GridView.ItemContainerStyle to change the style of the GridViewItem , but it doesn't seem to work with binding (although it works if I set the value to Collapsed).
<GridView.ItemContainerStyle> <Style TargetType="GridViewItem"> <Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource booleanToVisibilityConverter}}" /> </Style> </GridView.ItemContainerStyle>
I also tried using DataTemplateSelector . I can hide the elements with binding, but then there are spaces in my GridView , because the ItemContainer still exists, and not compressed .
I need the GridView items to be collapsed, not just hidden.
EDIT: Why do I want to get rid of filtered ObservableCollections ?
I am trying to mirror 2 GridViews and 1 ListView with the same ItemsSource and SelectedItem that are bound to my ViewModel Items and Current properties. Without filters, it works as I expect, without SelectionChanged events, but with only two-way binding .
But those GridView/Listview should have some differences, such as selectable items and DataTemplates . Therefore, I use filtered collections that brought me problems.
For instance:
GridView1 has items 1, 2, and 3GridView2 has only items 1 and 3- I choose Item 1 from
GridView1 - I select item 2 from
GridView1
When I select Item 1, it is also selected on GridView2 . It's good now. When I select item 2, item 1 supports the one selected on GridView2 . GridView2 should now be without a choice, but if I force it, it always deselects the 2nd item of GridView2 , since SelectedItem for both two-way binding.
I hope this is understandable, because English is not my native language.