Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
My Scenario:

Two ListBoxes - Listbox_01 and Listbox_02.
Listbox_01 ItemsSource is bind to a ObservableCollection in a ViewModel, SelectionMode set to Multiple, with attached property to limit the selection to 2 items. SelectedItems (dependency property) is bind to a property (IList) on ViewModel
Listbox_02 ItemsSource is bind to a property (IList) on a ViewModel (SelectedItems from Listbox_01). SelectionMode set to Single.
When I select items from Listbox_01 all should appear in a Listbox_02. This works for me. The question is, How can I link these two Listboxes to select and deselect items between them.
If I select two items from Listbox_01 they will be visible in Listbox_02. Then, when I select item from Listbox_02 it should get selected item (columns or content), fire command (RelayCommand), deselect that item on Listbox_01 and disappear from Listbox_02.

The problem here is that, when I click on Listbox_02 item there is always selection on Listbox_01 and the item that disappear from Listbox_02 is not correct (when I have two items, I click on the item_02 to close it, item_01 disappears)

Listbox_01 is only for selecting items. Listbox_02 is to execute command.

My code:
Listbox_01
XML
<listv:ListViewSelectedItemBehavior SelectionMode="Multiple"
                                    ItemsSource="{Binding EmployeeViewM.MainActivity}"
                                    SelectedItemsList="{Binding EmployeeViewM.SelectedAll, Mode=OneWayToSource}"
                                    Background="{x:Null}"
                                    BorderBrush="{x:Null}"
                                    IsSynchronizedWithCurrentItem="False" >


Listbox_02
XML
<listv:ListViewSelectedItemBehavior SelectionMode="Single"
                                    HorizontalAlignment="Left"
                                    ItemsSource="{Binding EmployeeViewM.SelectedAll}"
                                    SelectedItemsList="{Binding EmployeeViewM.SelectedAll, Mode=TwoWay}"
                                    Background="{x:Null}"
                                    BorderBrush="{x:Null}"
                                    IsSynchronizedWithCurrentItem="False">


SelectedAll IList

VB
Public Property SelectedAll() As IList
    Get
        Return _selectedAll
    End Get
    Set(value As IList)
        _selectedAll = value
        RaisePropertyChanged("SelectedAll")
    End Set
End Property


What I have tried:

SelectedIndex, SelectedItem, DataGrid instead of ListBox,
Posted
Updated 17-May-16 23:28pm

1 solution

Solved thanks to this article:
Managing Multiple selection in View Model (.NET Metro Style Apps)[^]

Thank you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900