c# - MVVM: Convert code-behind to XAML -


i've got alltopicsviewmodel , got property exercisevm allexerciseviewmodel, since want able refresh allexerciseviewmodel of exerciseview doing (not sure if violates mvvm, pls. tell me). well, want convert 2 lines following initializecomponent xaml not sure how, can me out?

  public mainwindow()     {         initializecomponent();          alltopicsviewmodel vm = (alltopicsviewmodel)topicsview.datacontext;         vm.exercisevm = (allexercisesviewmodel)exercisesview.datacontext;      } 

yes, misconception, according idea of mvvm.

ideally, view's codebehind (view.xaml.cs) contains nothing more auto generated code. view accesses viewmodel via wpf's data binding mechanisms. because data binding via wpf loose coupling between binding view , bound-to viewmodel, achieve seperation drives people use mvvm.

you retrieving viewmodel in views codebehind control's datacontexts. this, create strong reference between view , viewmodel. so, question: should think trying to viewmodel in view's codebehind , how can differently, either in view's xaml or in viewmodel's code itself.

if like, post complete mainwindow() class advice...

edit:

ok, setting child viewmodel on parent viewmodel. parent viewmodel alltopicsviewmodel should responsible setting own exercisevm on initialization. not view's job. parent viewmodel should assemble data 1 or more models , create child view models view consumes. make sense you?


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -