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

  • Home
  • SEARCH
  • 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 8924521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:26:37+00:00 2026-06-15T07:26:37+00:00

I have a WPF ListBox in Extended SelectionMode. What I need to do is

  • 0

I have a WPF ListBox in Extended SelectionMode.

What I need to do is bind the ListBox to an observable collection of a data item class, which is easy, but essentially, bind the IsSelected status of each ListBoxItem to a boolean property in the respective data item.

And, I need it to be two-way, so that I can populate the ListBox with selected and unselected items from the ViewModel.

I’ve looked at a number of implementations but none work for me. They include:

  • Adding a DataTrigger to the ListBoxItem’s style and calling a state action change

I realise this can be done in code-behind with an event handler, but given the complexity of the domain it would be horribly messy. I’d rather stick to two-way Binding with the ViewModel.

Thanks.
Mark

  • 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-15T07:26:38+00:00Added an answer on June 15, 2026 at 7:26 am

    In WPF you can easily bind your ListBox to a collection of items with a boolean property for the IsSelected state. If your question is about Silverlight, i’m afraid it won’t work the easy way.

    public class Item : INotifyPropertyChanged
    {
        // INotifyPropertyChanged stuff not shown here for brevity
        public string ItemText { get; set; }
        public bool IsItemSelected { get; set; }
    }
    
    public class ViewModel : INotifyPropertyChanged
    {
        public ViewModel()
        {
            Items = new ObservableCollection<Item>();
        }
    
        // INotifyPropertyChanged stuff not shown here for brevity
        public ObservableCollection<Item> Items { get; set; }
    }
    

    <ListBox ItemsSource="{Binding Items, Source={StaticResource ViewModel}}"
             SelectionMode="Extended">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="IsSelected" Value="{Binding IsItemSelected}"/>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding ItemText}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF listbox and have updated the list item data template to
I have a wpf application using Caliburn.Micro. I need to bind a ListBox to
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have defined style for my WPF listbox but am adding a rectangle manually
If I have a WPF listbox and I bind its itemssource to a list
I have a WPF application with ListBox that display list of items. Each item
I have a WPF ListBox control and I'm setting its ItemsSource to a collection
I have some WPF ListBox which is dynamically populating with items. Something like this
I have a wpf-mvvm application. I have an observable collection in my viewmodel public
I have a ListBox which I bind to an ObservableCollection<Series> in the view model.

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.