This project is read-only.

MVVM Finish and Cancel

Apr 16, 2014 at 4:33 PM
Hello.

I'm trying to figure out how to bind the IWizardController.FinishRequested event with the Finish event of the Wizard. Same things for the Cancel event/button

I've never used Behavior but looking into the code it seems to me that those events handler are propagated if the WizardController changes but they are never bound to the underlying Wizard object.

Thank you,
Alessio
Apr 24, 2015 at 8:22 PM
Edited Apr 24, 2015 at 10:13 PM
I've done as following:

Added to Wizard.cs a Dependency Property for Cancel Command
        /// <summary>
        /// Gets or sets the command of the Cancel button.
        /// </summary>
        public ICommand CancelCommand
        {
            get { return (ICommand)GetValue(CancelCommandProperty); }
            set { SetValue(CancelCommandProperty, value); }
        }

        /// <summary>
        /// Identifies <see cref="CancelCommand"/> dependency property.
        /// </summary>
        public static readonly DependencyProperty CancelCommandProperty =
            DependencyProperty.Register("CancelCommand", typeof(ICommand), typeof(Wizard));

        #endregion [CancelCommand]
Fire the command inside the Wizard.Cancel Method:
        public virtual void Cancel()
        {
            if (CancelCommand != null)
                CancelCommand.Execute(null);

            OnCancelled(new RoutedEventArgs());
        }
Bind your command like this:
        <wizard:Wizard WizardStyle="Wizard97" CancelCommand="{Binding OnCancel}">
            <i:Interaction.Behaviors>
                <mvvm:WizardMvvmBehavior ItemsSource="{Binding Pages}" Controller="{Binding WizardController}"/>
            </i:Interaction.Behaviors>
        </wizard:Wizard>
Repeat the above steps for the Finish Command ;)