Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Answer
How to get items in ViewModel from Multiselect Listbox -MVVM
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Math Ew
8y
539
1
Reply
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
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
ImageSource to byte arrary convertion
Disabling a UserControl w.r.t another usercontrol