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 }
    );

Last edited Aug 22, 2010 at 2:29 PM by stovellp, version 3

Comments

No comments yet.