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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:34:34+00:00 2026-05-23T01:34:34+00:00

I have a ListBox that can have multiple items selected at once. I have

  • 0

I have a ListBox that can have multiple items selected at once. I have a UserControl that needs needs to be visible if exactly one item in the ListBox is selected.

Here is the pane that needs to be hidden:

<views:WebMethodsPane x:Name="WebMethodsPane"  Grid.Column="1" Grid.Row="0"   Margin="5,5,5,0" 
Visibility="{Binding SelectedList, Converter={StaticResource SelectionToVisibilityConverter}}" />

The SelectedList object is an ObservableCollection that is filled with items that are selected by the user in the ListBox. (I used a behavior to do this.)

The SelectionToVisibilityConverter goes as follows:

public class SelectionToVisibilityConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var selectedServices = value as ObservableCollection<WebService>;
        return (selectedServices.Count == 1 ? Visibility.Visible : Visibility.Collapsed);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

When I run the app, the pane is hidden and stays hidden. The visibility is not being updated when I select different numbers of items from the ListBox. How can I make sure the Visibility updates? Maybe I need to use INotifyPropertyChanged, but I don’t know exactly how to.

  • 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-23T01:34:35+00:00Added an answer on May 23, 2026 at 1:34 am

    The approach I would take would be to add a new property to the bound object, a SingleItemSelected boolean property.

    Something along the lines of:-

     public class YourClass : INotifyPropertyChanged
     {
    
         public ObservableCollection<WebService> SelectedList {get; private set; }
    
         // ctor
         public YourClass()
         {
             SelectedList = new ObservableCollection<WebService>();
             SelectedList.CollectionChanged += SelectedList_CollectionChanged;
         }
    
         private void SelectedList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
         {
             SingleItemSelected = SelectedList.Count == 1;
         }
    
         private bool mySingleItemSelected
         public bool SingleItemSelected
         {
             get { return mySingleItemSelected; }
             private set
             {
                  if (mySingleItemSelected != value)
                  {
                       mySingleItemSelected = value;
                       PropertyChanged(this, new PropertyChangedEventArgs("SingleItemSelected"));
                  }
             }
         }
    
         public event PropertyChangedEventHandler PropertyChanged = delegate {};
    
    }
    

    So now what you need is a simple BoolToVisibilityConverter, there are plenty of examples of such a thing, I prefer my own here.

    Then you xaml (assuming you placed an instance of the converter in the resources with the key “BtoV”):

    <views:WebMethodsPane x:Name="WebMethodsPane"  Grid.Column="1" Grid.Row="0" Margin="5,5,5,0"
        Visibility="{Binding SingleItemSelected, Converter={StaticResource BtoV}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Listbox that allows user to select multiple items. Normally user can
I would like to make a multiple selection listbox in HTML that can have
I have a ListBox that when in focus, and when I have an item
I have a ListBox that during development I had the items in the ListBox
I have a listbox that I'm doing some databinding. As you can see I
I have a listbox that might contain thousands of items. I need a way
I have a UserControl that contains a ListBox that is bound to a CollectionViewSource
I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have a listbox that is databound to a Collection of objects. The listbox
I have a ListBox control that I want to change into having a toggle

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.