TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Math Ew
NA
5
8k
How to get items in ViewModel from Multiselect Listbox -MVVM
May 25 2016 3:50 AM
Hi,
I have 3 ListBoxes in my app.
ListBox_01
ItemsSource
=
"{Binding EmployeeViewM.MainActivity}"
EmployeeViewM is a ViewModel defined in ViewModelLocator using Ioc.
MainActivity is an ObservableCollection bind to the Model - table with activities via EntityFramework.
- SelectionMode = "Multiple"
- Limit to selected items set to 2
<
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
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):
private
IList _selectedAll =
new
ArrayList();
public
IList SelectedAll {
get
{
return
_selectedAll; }
set
{
_selectedAll = value;
RaisePropertyChanged(
"SelectedAll"
);
}
}
ListBox_02
is the same like
ListBox_0
1, 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
.
ItemsSource
=
"{Binding EmployeeViewM.SelectedAll}"
ItemsSource for this ListBox is SelectedAll.
Scenario:
Employee select activity from
ListBox_01
. This should execute RelayCommand from ViewModel via SelectionChange to get which activity has been chosen by an employee, get attributes for this activity (attribute (Name, Group, Process etc) comes from Entity to which ListBox is bind via ItemsSource) save activity (attributes) to the database/entity, get ID from entity, and run DispatcherTimer to calculate time of activity, this activity should be visible on
ListBox_03
, if an employee will select another activity from
ListBox_01
or
Listbox_02
, the scenario is similar but it should stop previous activity and get all attributes for newly selected activity. I'm not able to get those items in ViewModel and my SelectedAll has no columns, and I'm not able to bind IsSelected to it,
hope someone will be able to help me with this case...
Thank you for any suggestion
Reply
Answers (
0
)
ImageSource to byte arrary convertion
Disabling a UserControl w.r.t another usercontrol