Magellan Commands

Back to: Magellan Home

The web typically uses hyperlinks and postbacks to navigate between pages. With Magellan, we can use either C# code, Expression Blend Behaviors, or using a command.

The command option works especially well for Magellan applications that use the MVVM pattern. Below is an example controller:

public class CustomerController : Controller 
{
    public ActionResult Show(int customerId)
    {
        Model = new CustomerDetailsModel(GetCustomer(customerId));
        return Page();
    }

    public ActionResult Delete(int customerId)
    {
        DeleteCustomer(customerId);
        return Redirect("Home");
    }
}

The CustomerDetailsModel may look like this:

public class CustomerDetailsModel
{
    public CustomerDetailsModel(Customer customer) 
    {
        Customer = customer;
        DeleteCustomer = new NavigateCommand("Customers", "Delete", new { customerId = customer.Id });
    }

    public ICommand DeleteCustomer { get; private set; }
    public Customer Customer { get; private set; } 
}

The view can then simply bind the command to the UI elements:

<Button Content="Delete" Command="{Binding Path=DeleteCustomer}" />

Most MVVM frameworks also provide a RelayCommand or DelegateCommand or similar that allows you to pass a callback. This could also be used with Magellan; for example:

DeleteCommand = new DelegateCommand<Customer>(
    customer => Navigator.Default.Navigate("Customers", "Delete", new { customerId = customer.Id }
    );

See also:

Back to: Magellan Home

A picture of me

Welcome, my name is Paul Stovell. I live in Brisbane and work on Octopus Deploy, an automated deployment tool for .NET applications.

Prior to founding Octopus Deploy, I worked for an investment bank in London building WPF applications, and before that I worked for Readify, an Australian .NET consulting firm. I also worked on a number of open source projects and was an active user group presenter. I was a Microsoft MVP for WPF from 2006 to 2013.