Updated: Avalon Wizard MVVM Project

Here’s an updated version of the Avalon Wizard MVVM Project that I posted about a while ago.

This newly updated solution contains step navigation along the right hand side. Also, I’ve included a test solution for testing. Just a note, the testing project is pretty rough. I haven’t commented it much as I didn’t really think I’d include it. I have been just using it for internal testing. When I get a moment I’ll go through and explain what I’m testing and how everything works.

For now I wanted to touch on a few things that I are in the testing app. I was asked for an example where the pages can communicate with each other.

When I want to have my pages “push” updated information I use the Messaging system built into the Galasoft MVVM library. Here’s an example of the code pushing an update when the current page is being navigated away to the next page.

protected override void CommitRaised(object sender, System.Windows.RoutedEventArgs args, WizardPageViewModelBase viewModel)
{
  //send information to the summary page via a message
  Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(this, this.InfoText));
}

On the summary page you can see in the constructor of the view model I am setting up the “listener” for the messages. In the handler function I update a dictionary with the messages received.

public SummaryPageViewModel()
{
  this.Header = "Summary";
  this.StepName = "Summary";

  //register a message listener
  Messenger.Default.Register<GenericMessage<string>>(this, this.MessageHandler);
}

void MessageHandler(GenericMessage<string> message)
{
  //if the message wasn't sent by a page view model we don't want it.
  WizardPageViewModelBase sender = message.Sender as WizardPageViewModelBase;

  if (sender == null)
    return;

  //lets anyone watching the dictionary know it's about to change
  RaisePropertyChanging(MessagesPropertyName);

  if (_Messages.ContainsKey(sender))
    _Messages[sender] = message.Content;
  else
  {
    _Messages.Add(sender, message.Content);
  }

  //alerts the view that we've changed the dictionary
  RaisePropertyChanged(MessagesPropertyName);
}

The other way I could do this would be to have the Summary page use a ViewModelLocator to get the references to each page and then extract the data I needed from the public properties.

Download the updated project here: Avalon Wizard MVVM Project

About Mike

I'm a software engineer. Look into the about page for more information about me.
Tagged , , . Bookmark the permalink.

2 Responses to Updated: Avalon Wizard MVVM Project

  1. Vivian Lobo says:

    Thanks for so much help here Michael. I have borrowed some of your source and trying to learn Avalon for my personal projects.

    • Mike says:

      Cool! Just as an FYI there may already be an MVVM version out of Avalon Wizard. I vaguely remember seeing that on their site when I was checking to see if there was ever an update. For the longest time I thought the project was semi-abandoned.

      I’m around on github. Let me know if you have any projects using the code as I would love to see what you’re using it to accomplish!

Leave a Reply