Datacontext is null

Jul 14, 2013 at 3:36 AM
I'm trying to reference the viewmodel from the view and I can't. It appears you can't instantiate an instance of the viewmodel because I can't pass a navigation context. So, I figured it had to already be instantiated (I have a version of this working where I reference the ViewModel with static methods but that's sloppy to me). So, I tried to cast the datacenter as the viewmodel and discovered that it's null. What would I be doing wrong? Or is there another way to reference the viewmodel from the view?

Sorry for so many questions, but I'm completely new to this framework.

Thanks.
Coordinator
Jul 16, 2013 at 8:33 PM
Hi,

I think this is related to your previous problem with your view-model not being bound to the view correctly. With the Okra App Framework you should never be creating the view-model yourself - just let the framework handle that for you.

Regarding the best way to access the view-model from the view, the recommended approach is to cast the DataContext to the type of the view-model as you correctly suggested. If the DataContext is 'null' then this suggests that Okra has never tried to create the view-model. Check out my suggestions in my previous post and get back to me if you are still struggling.

Regards,
Andy