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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:58:30+00:00 2026-05-18T19:58:30+00:00

Being a new to WPF/XAML/MVVM, I’ve got a question. In my View, I have

  • 0

Being a new to WPF/XAML/MVVM, I’ve got a question.

In my View, I have 2 listboxes, which derive from ItemsControl.
On my viewmodel, I’d like to expose 2 ItemsControl properties such that I can bind my listbox to this view model property… this way I can implement a command that, from the view model, lets me move the currently selected item from ListBox1 to ListBox2.

Imagine all the really cool stuff not shown the following snippets:

view model code:

public int MyStuff1SelectedIndex { get{...} set{...} }
public int MyStuff2SelectedIndex { get{...} set{...} }
public ItemsControl MyStuffItemsControl1 { set; private get; }
public ItemsControl MyStuffItemsControl2 { set; private set; }

view XAML:

   <ListBox Name="x:MyStuffListBox1" SelectedIndex="{Binding MyStuff1SelectedIndex}.... />
   <ListBox Name="x:MyStuffListBox2" SelectedIndex="{Binding MyStuff2SelectedIndex}...../>

given that, I want my viewmodel to be able to have a command which could move items from one list box to another, w/ code such as the following:

public void MoveItemCommandExecute(...)
{
   var sourceItem = MyStuff1ItemsControl.MagicGetItemExtensionMehod(MyStuff1SelectedIndex);
   MyStuff1ItemsControl.MagicRemoveItemExtensionMethod(MyStuff1SelectedIndex);

   MyStuff2ItemsControl.MagicAddItemExtensionMethod(sourceItem);
}

so, basically, what would the binding XAML look like ? I am trying to set a property on the view model from the view…

thanks!

  • 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-18T19:58:31+00:00Added an answer on May 18, 2026 at 7:58 pm

    You’ll want to rethink this approach. Typically, you would bind your two listboxes ItemsSource properties to two ObservableCollection<T> properties on your view model, where T is the type of object in your list.

    <ListBox x:Name="MyStuffListBox1" ItemsSource="{Binding MyList1}" SelectedItem="{Binding SelectedList1Item}" />
    <ListBox x:Name="MyStuffListBox2" ItemsSource="{Binding MyList2}" SelectedItem="{Binding SelectedList2Item}" />
    

    Note: I would use x:Name in your XAML, rather than the Name attribute.

    public ObservableCollection<Thing> MyList1 { get; set; }
    public ObservableCollection<Thing> MyList2 { get; set; }
    
    // these properties should raise property changed events (INotifyPropertyChanged)
    public Thing SelectedList1Item { get {...} set {...} }
    public Thing SelectedList2Item { get {...} set {...} }
    
    // constructor 
    public MyViewModel()
    {
      // instantiate and populate lists
      this.MyList1 = new ObservableCollection(this.service.GetThings());
      this.MyList2 = new ObservableCollection(this.service.GetThings());
    } 
    

    You can then format what is displayed in the lists using DisplayMemberPath or defining an ItemTemplate on each list.

    You can swap items between the lists by using the standard Collection methods on the ObservableCollection type – http://msdn.microsoft.com/en-us/library/ms668604.aspx

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

Sidebar

Related Questions

Being a new to WPF/XAML/MVVM, I've got a question. In my View, I have
Being new to both WPF and MVVM, I'm studying Josh Smith's article on the
being new to WPF this is a complex problem for me. What i want
While designing a new WPF application I noticed exceptions not being thrown during data
I've got a Border in XAML/WPF that I'm using to give a full-paragraph-width underline
I am trying to modify App.cs and load the WPF XAML files from code
I have the following binding in my wpf application xaml: <TextBox Text={Binding Amount, StringFormat=c}
I'm not new to WPF or C# but I am new to MVVM and
I have a WPF application using MVVM; when I change the ViewModel in my
I have a WPF MVVM app that contains an editable DataGrid. I am subscribing

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.