Magellan Commands

This is an old post and doesn't necessarily reflect my current thinking on a topic, and some links or images may not work. The text is preserved here for posterity.

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