1

My issue seems to be one that others have as well, as I've found a few other questions that are similar (e.g. WPF - hiding listbox items). In that particular question/answer, I've gotten further than anything else I've found combined. The problem I'm facing is that when I implement the DataTrigger as it is in the answer there (slightly modified for ListView as opposed to ListBox), I get the proper collapsing of the item, but for certain things, my theme appears to be reverted to the defaults instead of using my ModernUI styling.

Here is what I've added to my ListView in order to get the collapsed items to truly be collapsed:

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Visibility}" Value="Collapsed">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

Here is an example of the items filtered before adding the above: Before the <Style/>

(notice the orange hover of an item that's not supposed to be there)

Here is an example of the items filtered after adding the above: After the <Style/>

(notice the hover/selection indicator is now somehow blue, and my text fields no longer size appropriately)

Any help that anyone can provide will be much appreciated, and thanks already for taking the time to read this.

Side-note: Please don't just tell me to use the CollectionView to filter. I spent the majority of my day yesterday fighting with that, and because of using a BindingList<> instead of an ObservableCollection<>, it simply won't work for my situation.

11
  • Side note: Why are you using a BindingList in WPF? Mar 17, 2016 at 14:16
  • 1
    Add the BasedOn attribute on this style so that is inherits the theme's style.
    – Mike Eason
    Mar 17, 2016 at 14:24
  • 1
    Hmm, how about BasedOn="{StaticResource {x:Type ListViewItem}}". That should base it on whatever the default style of ListViewItem is. I haven't tried it using your example but it's worth a shot.
    – Mike Eason
    Mar 17, 2016 at 14:30
  • 1
    You can use snoopwpf.codeplex.com Mar 17, 2016 at 14:30
  • 1
    @MikeEason You are my hero! Please make that comment an answer so I can give you some much deserved answer points you beautiful, beautiful man.
    – Lance
    Mar 17, 2016 at 14:34

1 Answer 1

2

The problem here is that the ModernUI framework overrides the default style of the ListViewItem, however you are overriding this:

<Style TargetType="{x:Type ListViewItem}">

Now your style becomes the new default style for a ListViewItem. To fix this, use the BasedOn attribute to inherit the ModernUI style.

<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">

The code above simply inherits the default ListViewItem style (which has been overridden by ModernUI).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.