Click here to Skip to main content
15,884,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are 2 different views in which I handle the enable disable of different buttons one in the context menu but another in ribbon bar, Context menu, and ribbon bar is present n different 2 views. Enable disable of these buttons are based on the same operation which is defined in the view model. For this implementation, I am using event aggregator to communicate between view models of these views. Instead of this method I want to use composite command how will I implemented by using composite command

What I have tried:

I have implemented using event aggregator
Posted
Updated 12-Dec-17 17:39pm
v2

If you know what to search for it shouldn't be that difficult:
DelegateCommand and CompositeCommand in Prism[^]
 
Share this answer
 
Depending on how it's being used, you could declare the CompositeCommand as an exported class. Then each view model could import the CompositeCommand and register it's own command.

[Export]
public class SaveWidgetsCompositeCommand : CompositeCommand { }

[Export]
public class FrontWidgetViewModel
{
    DelegateCommand FrontSaveCommand { get; set; }

    [ImportingConstructor]
    public FrontWidgetViewModel( SaveWidgetsCompositeCommand saveCommand)
    {
        saveCommand.RegisterCommand(FrontSaveCommand);
    }
}

[Export]
public class BackWidgetViewModel
{
    DelegateCommand BackSaveCommand { get; set; }

    [ImportingConstructor]
    public BackWidgetViewModel(SaveWidgetsCompositeCommand saveCommand)
    {
        saveCommand.RegisterCommand(BackSaveCommand);
    }
}


If you want to do it with a CompositeCommand via the view, the CompositeCommand would need to be declared in the view and it would need to register the two commands from the view models on binding/instantiation.

As a note, this approach may also require unregistering the view model commands to avoid leaks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900