3
\$\begingroup\$

I am currently in the process of learning WPF Prism and I have four buttons that I want to all go to the same place but with a different value being passed depending on which button has been pressed.

Below is the code that I currently have.

ApplicationCommands.cs

public class ApplicationCommands
{
    public static CompositeCommand LoginCommand = new CompositeCommand();
    public static CompositeCommand TotalOutstandingCommand = new CompositeCommand();
    public static CompositeCommand InSLACommand = new CompositeCommand();
    public static CompositeCommand GoingOOSLACommand = new CompositeCommand();
    public static CompositeCommand OOSLACommand = new CompositeCommand();
}

DashboardViewModel.cs

...
public DelegateCommand<object> TotalOutstandingCommand { get; set; }
public DelegateCommand<object> InSLACommand { get; set; }
public DelegateCommand<object> GoingOOSLACommand { get; set; }
public DelegateCommand<object> OOSLACommand { get; set; }

public DashboardViewModel(IDashboardView view, IRegionManager manager)
        : base(view)
    {
        _regionManager = manager;

        TotalOutstandingCommand = new DelegateCommand<object>(GoToAllocation);
        InSLACommand = new DelegateCommand<object>(GoToAllocation);
        GoingOOSLACommand = new DelegateCommand<object>(GoToAllocation);
        OOSLACommand = new DelegateCommand<object>(GoToAllocation);

        ApplicationCommands.TotalOutstandingCommand.RegisterCommand(TotalOutstandingCommand);
        ApplicationCommands.InSLACommand.RegisterCommand(InSLACommand);
        ApplicationCommands.GoingOOSLACommand.RegisterCommand(GoingOOSLACommand);
        ApplicationCommands
}

private void GoToAllocation(object value)
{
       //Logic Goes Here
}

I was curious to know if there is a simpler way to complete the task or do I need to declare and register a separate DelegateCommand for each button

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.