N.J
N.J

Reputation: 1230

Changing Command based on ViewModels

In my project I have many Views and Viewmodels each view is selected using the current active viewmodel. Everything works fine, I have a toolbox in my project with few buttons basically options to "Save", "Delete" etc. This toolbox is Common for all views.
Here is my real problem starts i want to trigger the Command based on the Current View model like how I am loading all the views. For example there is a SaveCommand in all Viewmodel how will i trigger the Command associated with the "Current Viewmodel".
Is this even possible? or Am I completely wrong?

Upvotes: 0

Views: 52

Answers (1)

Toni Petrina
Toni Petrina

Reputation: 7112

You should simply use the following binding:

Command={Binding CurrentViewModel.SaveCommand}

This will always bind to the SaveCommand found on the CurrentViewModel and when/if you change the current VM, this will automatically rebind itself.

I assume that the master view model contains such "current" or active view model as its own property.

Upvotes: 1

Related Questions