I created a custom user control that retrieve rows from database and will create all the buttons on runtime. My current approach is write all codes in the code behind of user control. And also I add a click event handler to each buttons that created
on runtime. When any of the button is clicked, inside the click handler function will raise a RoutedEvent.
And at the parent control, I add a handler to the custom user control to handle which button is clicked.
The problems is :
1) I don't want to write all codes at the code behind. I tried to create a view model class for the user controls, but I failed to bind the event to view model as I wanted to retrieve the object that call this event. ICommand doesn't provide the information
2) Even if I successful created a view model class, when a click event is triggered, the view model will handle it then it fire another event to user control class then the user control class fire another event to the main parent control. Which I think this
is stupid >_<
3) I want to know how to user MVVM in this situation.
Thanks & Regards,
View Complete Post