Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:31:00+00:00 2026-05-23T20:31:00+00:00

I was hoping to collapse certain ListBoxItems based on a property of their data

  • 0

I was hoping to collapse certain ListBoxItems based on a property of their data context.

I came up with the following (trimmed for brevity)

<ListBox ItemsSource="{Binding SourceColumns}">
     <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
              <DataTrigger Binding="{Binding IsDeleted}" Value="True">
                 <Setter Property="Visibility" Value="Collapsed"/>
              </DataTrigger>
            </Style.Triggers>
         </Style>
      </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
       <DataTemplate>
         <TextBlock VerticalAlignment="Center" Margin="5,0" Text="{Binding ColumnName}"/>
       </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

This “works” in that it does collapse the listboxitems that are marked as “IsDeleted”, however the vertical scrollbar does not adjust for the “missing” items. As I’m scrolling, all of a sudden the bar gets bigger and bigger (without moving) until I scroll past the point of the hidden items, and then finally starts to move.

I also tried explicitly setting the height and width to 0 as well in the data trigger, to no avail.

Does anyone know if there’s a workaround for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:31:00+00:00Added an answer on May 23, 2026 at 8:31 pm

    Enter CollectinViewSource

    One thing you can do is connect your ListBox to your items through a CollectionViewSource.

    What you do is create the collectionViewSource in XAML:

    <Window.Resources>
        <CollectionViewSource x:Key="cvsItems"/>
    </Window.Resources>
    

    Connect to it in your CodeBehind or ViewModel

    Dim cvsItems as CollectionViewSource
    cvsItems = MyWindow.FindResource("cvsItems")
    

    and set it’s source property to your collection of items.

    cvsItems.Source = MyItemCollection
    

    Then you can do filtering on it. The collectionViewSource maintains all of the items in the collection, but alters the View of those items based on what you tell it.

    Filtering

    To filter, create a CollectionView using your CollectionViewSource:

    Dim MyCollectionView as CollectionView = cvsItems.View
    

    Next write a filtering function:

    Private Function FilterDeleted(ByVal item As Object) As Boolean
        Dim MyObj = CType(item, MyObjectType)
        If MyObj.Deleted = True Then Return False Else Return True End If
    End Function
    

    Finally, write something that makes the magic happen:

    MyCollectionView .Filter = New Predicate(Of Object)(AddressOf FilterDeleted)
    

    I usually have checkboxes or Radiobuttons in a hideable expander that lets me change my filtering options back and forth. Those are bound to properties each of which runs the filter function which evaluates all the filters and then returns whether the item should appear or not.

    Let me know if this works for you.

    Edit:

    I almost forgot:

    <ListBox ItemsSource="{Binding Source={StaticResource cvsItems}}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping someone can shed some light on this: Do lookup tables need their own
I have XAML similar to this: <ListBox ItemsSource={Binding SearchCriteria, Source={StaticResource model}} SelectionChanged=cboSearchCriterionType_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>
Hoping this is trivial for a SQL-Ninja... Been trying to get the following query
Hoping somebody can help me out - I would like to replace a certain
Hoping for a quick answer here. OK, since I do a lot of single
Hoping this is just a case of syntax. I'm writing a custom search function
Hoping someone can help. I am working on an aspx site, using the c#
Hoping that someone can help clear up this very annoying situation I find myself
Hoping someone with a better knowledge of javascript can assist, I am wanting to
Hoping Paul McGuire may spot this and rescue me... I have grabbed the 'regex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.