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 8311747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:54:51+00:00 2026-06-08T19:54:51+00:00

I have a listbox with a bit of templating. Groups are represented by expanders.

  • 0

I have a listbox with a bit of templating. Groups are represented by expanders. The listbox is linked to the filesystem and each folder gets its own expander. Any time a file is renamed, deleted, etc, the listbox’s view is refreshed. This works great but once the refresh is called, each of the expanders collapses. I can’t seem to find a good way to keep them open. I saw another question that used binding to solve this for a single expander. The issue with a data binding on the “IsExpanded” is that there are an unknown number of expanders and I have no way of knowing how many there will be, what they will be called, etc at design time. Any ideas?

<ListBox.GroupStyle>
        <GroupStyle>
           <GroupStyle.ContainerStyle>
              <Style TargetType="{x:Type GroupItem}">
                 <Setter Property="Template">
                    <Setter.Value>
                       <ControlTemplate TargetType="{x:Type GroupItem}">
                          <Expander VerticalAlignment="Top"
                              OverridesDefaultStyle="True"
                              Template="{StaticResource SimpleExpanderTemp}">
                             <Expander.Header>
                                <TextBlock VerticalAlignment="Center"
                                     Background="Transparent"
                                     Text="{Binding Path=Name}"
                                           FontFamily="SegoeUI"
                                     FontSize="16"
                                     Foreground="Black"/>
                             </Expander.Header>
                             <Expander.Tag>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                   <GradientStop Offset="0.0" Color="#696969" />
                                   <GradientStop Offset="1.0" Color="#474747" />
                                </LinearGradientBrush>
                             </Expander.Tag>
                             <ItemsPresenter/>
                          </Expander>
                       </ControlTemplate>
                    </Setter.Value>
                 </Setter>
              </Style>
           </GroupStyle.ContainerStyle>
        </GroupStyle>
     </ListBox.GroupStyle>
  • 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-06-08T19:54:53+00:00Added an answer on June 8, 2026 at 7:54 pm

    One possible solution is to still use data binding on the IsExpanded property.

    Instead of binding to a boolean, bind to a list of booleans and use a ValueConverter to retrieve the appropriate item from the list.

    When creating all your expanders, give each one an index number, if you’re not already. Then when you bind the IsExpanded property, set the Converter, and set the converter parameter to the index number of the expander. Then your converter will receive the list of boolean values as the ‘value’ argument and the index number as the ‘parameter’ argument and your converter can then return a boolean value.

    Your converter might look like this:

    public class ListToBooleanConverter : IValueConverter
    {
    
      public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
        if ((value != null) & (parameter != null)) {
          try {
            Int16 itmNum = Convert.ToInt32(parameter);
            List<bool> lst = value;
            return lst[itmNum];
          } catch (Exception ex) {
            return null;
          }
        }
          return null;
      }
    
      public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
        throw new NotImplementedException("This method or operation is not implemented.");
      }
    }
    

    In XAML, the implementation of this data binding and converter would look like this (for the expander with an index number of 5):

    IsExpanded="{Binding Path=ListIsExpanded, Converter={StaticResource ListToBooleanConverter}, ConverterParameter=5}">
    

    Obviously, in code, this implementation will look a little different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Each item in a WPF ListBox control seems to have a bit of left
I have a Pivot, nothing in the slightest bit unusual and the listbox displays
I have ListBox called lstProductGroups. On a simple Windows Form, a method called GetGroups
I have a ListBox and I need to repeat the styles to be the
I have a ListBox with multiple selection. And I am doing drag and drop
I have a listbox on a page: <select id=user_list name=user_list size=21 style=width:200px;> <option value=1>User
I have a ListBox with items that fill TextBox es. How do I identify
I have a listbox for a Windows Phone 7 app that displays info parsed
I have a listbox with multiselect options. I populate it using the addItem function.
I have a ListBox defined in my app that I've populated with some static

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.