Events from UserControl as ItemTemplate in WPF ListBox
In WPF, I have a ListBox with a UserControl as its ItemTemplate - all data shown ok. I have now added a text box for input in that user control. In an MVVM design, I want to take some action (re-calculate values) in the main window when the user edits the content of the text box in the 开发者_如何学Pythonuser control, in the item template, in the list box. Question is - how to propagate that event up to the model? The user control is bound to a business object and I can see the value being changed there ok (INotifyPropertyChanged is implemented in the BO), but, how to get that event up to the model (as opposed to the code-behind)? Any examples or pointers most welcome!
jas
I'm assuming, given that this is an MVVM application, that you are trying to propogate the text changed event up to the ViewModel.
You can do this without adding code behind in the View by using an Attached Property or a Behavior. There is actually a Behavior on the Expression Gallery that Invokes a command when you hit Enter in a TextBox. This could easily be reworked to fire a custom ICommand on your ViewModel whenever the TextBox changes its value (it's very similar in goals).
精彩评论