Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have 3 ListBoxes in my app.
ListBox_01
XML
ItemsSource="{Binding EmployeeViewM.MainActivity}"

EmployeeViewM is a ViewModel defined in ViewModelLocator using Ioc.
MainActivity is a ObservableCollection bind to the Model - table with activities via EntityFramework.
- SelectionMode = "Multiple"
- Limit to selected items set to 2
XML
<i:Interaction.Behaviors>
   <listb:ListBoxSelectedItemBehavior SelectedItems="{Binding EmployeeViewM.SelectedAll, Mode=TwoWay}"/>
   <limit:LimitSelectionBehavior Limit="2"/>
</i:Interaction.Behaviors>

- listb:ListBoxSelectedItemBehavior is an attached property to enable SelectedItems from ListBox
C#
public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<object>), typeof(ListBoxSelectedItemBehavior), new PropertyMetadata(new ObservableCollection<object>(), PropertyChangedCallback));

- SelectedAll is a property on EmployeeViewM ViewModel for SelectedItems (IList):
C#
private IList _selectedAll = new ArrayList();
public IList SelectedAll {
	get { return _selectedAll; }
	set {
		_selectedAll = value;
		RaisePropertyChanged("SelectedAll");
	}
}


ListBox_02 is the same like ListBox_01, the only difference is that it is bind to another table (NonProcess)

Employees are able to select items on both - max 2 items per ListBox.

All selected items will be visible in ListBox_03.
XML
ItemsSource="{Binding EmployeeViewM.SelectedAll}"


ItemsSource for this ListBox is SelectedAll.

This part works great, but, when employee click on the item in the ListBox_03 I would like to:
- get that selected item name and other attributes from table that it comes from (MainActivity or NonProcess) - best in columns (from IList columns are unknown)
- save that item via .SaveChanges() to another table

What I have tried:

IsSelected - Not able to bind to that property,
ICollection instead IList, ObservableCollection(of Object)
Posted

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