Event/method to override to perform operations before binding in MVVM
I'm trying to perform AOP operations on view models that is being binded in the views. I've read some concepts and examples on MVVM. I noticed the use of DataTemplate which listens to ViewM开发者_运维百科odel changes and performs the binding automatically.
I'd like to perform some initializations on the view model before binding, how can I do this with WPF/MVVM?
Thanks.
Ways of binding. . .
Through data context
view.DataContext = viewModel;
Through contents and templates
<DataTemplate DataType="{x:Type vm:SampleViewModel}"> <vw:SampleDisplayView /> </DataTemplate>
i'd like to intercept the view and viewmodel and initialize them before binding occurs.
Update: I was able to intercept the view model through DataContextChanged event. Now I need the view to be initialized as well.
I found a way to do this. I implemented ViewLocator as most toolkits have this.
ViewLocator is implemented through attached behavior, having me to look for the viewmodel and do initializations before assigning it to the datacontext.
精彩评论