arrow-left arrow-right brightness-2 chevron-left chevron-right circle-half-full dots-horizontal facebook-box facebook loader magnify menu-down RSS star Twitter twitter GitHub white-balance-sunny window-close
Magellan Commands
1 min read

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

Enjoying these posts? Subscribe for more

Subscribe now
Already have an account? Sign in
Paul Stovell's Blog

Hello, I'm Paul Stovell

I'm a Brisbane-based software developer, and founder of Octopus Deploy, a DevOps automation software company. This is my personal blog where I write about my journey with Octopus and software development.

I write new blog posts about once a month. Subscribe and I'll send you an email when I publish something new.

Subscribe

Comments

You've successfully subscribed to Paul Stovell's Blog.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.