Alexandre D.
Alexandre D.

Reputation: 711

Get the ViewModel through a UserControl

I am currently developing a Windows Phone application with the MvvmCross framework. Whence my question : How do I get an instance of the ViewModel of my UserControl? Because, UserControl does not provide any ViewModel field.

Upvotes: 1

Views: 46

Answers (1)

Alexandre D.
Alexandre D.

Reputation: 711

Ok sorry for the useless post.

There is a simple way to do that and I don't understand why I didn't think about that sooner.

Anyway, I manage to get my ViewModel through the code behind of my UserControl with the following code :

ListProjectsViewModel vm = DataContext as ListProjectsViewModel;

if(vm != null)
{
    // To Do
}

Upvotes: 1

Related Questions