0
votes

I have a WPF View where I create controls dynamically depending on the object type in a List that the View is bound to in the ViewModel. I have a Button on in the View that I have bound to a RelayCommand in the ViewModel but I also want to pass a CommandParameter to the Command. The dynamically create controls are of types ListBox, ComboBox, TreeView, RadionButton and CheckBox. So when I press the Button I want to get all selected/checked items in the controls and pass this a List with the CommandParamter.

I have figured out how to search for all selected/checked items and get the object of type Code(class name) and put them in a List if I use the Click event on the Button. I want to use the RelayCommand instead of using Click Event.

I have managed to bind the CommandParameter to the a Property that calls GetAllSelectedCheckedCodes() but it is only bound when the View is created.

Is it possible to have a property in the code behind that calls the function GetAllSelectedCheckedCodes() that is bound first when the Button Command is triggered.

Or is it possible to have multiple controls add/remove items in a List in the ViewModel when they are selected/unselected or checked/unchecked?

1
I think your question would have a better chance getting answered with a short code sample, it's a lot to read through and make sense out of - Alan

1 Answers

0
votes

Are you able to add a property to your class like IsSelected, or IsActive, and bind that to the the IsSelected or IsChecked property of the control? Then, when you want to act on the selected items, you could just grab all the items in the collection where IsActive == true.