This project has moved and is read-only. For the latest updates, please go here.

[Solved] Using Events of the Wizard

Oct 19, 2015 at 11:44 AM
Dear all

I am new to C# and object oriented but not new to programming.

I have been using the xctk extended toolkit for some short time now but I can not find one very simple thing.

How can I listen for a event been triggered on the Cancel or Apply buttons for the Wizard.
In the first page it states that events exist.

I was expecting to see them when I go for example IntroPage.Cancel (and see an event)
But I do not see a method or an event.

Do I need to make a delegate and point it to a general event for example with
IntroPage.RaiseEvent? Do I need to do some Binding in xaml?

Can someone please tell me how can I access those events?
And please remember be pedagogical the shorts answer do X,Y will not help me as I am a newbie.

Best regards
Gouzgounis.
Developer
Oct 19, 2015 at 1:48 PM
Hi,

Each WizardPage has only 2 events : "Enter" and "Leave". If you want to listen to the "Cancel" and "Next" events, you have to look in the Wizard (containing the Wizard Pages).

You can define it in XAML :
<xctk:Wizard Next="Wizard_Next"
                     Cancel="Wizard_Cancel"/>
with the callbacks in code behind :
private void Wizard_Next( object sender, Toolkit.Core.CancelRoutedEventArgs e )
    {
    }

    private void Wizard_Cancel( object sender, RoutedEventArgs e )
    {
    }
The callbacks will be called every time the "Next" or "Cancel" buttons are clicked.

Or you can do it all in code-behind :
 public WizardView()
    {
      InitializeComponent();

      _wizard.Next += Wizard_Next;
      _wizard.Cancel += Wizard_Cancel;
    }

 private void Wizard_Next( object sender, Toolkit.Core.CancelRoutedEventArgs e )
    {
    }

    private void Wizard_Cancel( object sender, RoutedEventArgs e )
    {
    }
Marked as answer by Gouzgounis on 10/21/2015 at 1:01 AM
Oct 20, 2015 at 8:52 AM
Hi BoucherS

Thank you very much for your answer.

I have two question.

1) Why is the next event using the CancelRoutedEvent and the cancel is using a simpel RoutedEvent?

2) if I make it all in the code behind the _wizard.Next what does this mean? as I have no arguments in my method which is
 public wizardwindow () 
{
   InitializeComponent();
}
Where does the _wizard comes from?

As I said newbie here please be patient.

thank you again for your answer and time you spend with my silly beginners questions :-)

best regards
Gouzgounis.
Developer
Oct 20, 2015 at 8:00 PM
Hi,

1) There are 6 events on the Wizard control. 2 of them (Next and Previous) can be cancelled by the user by setting e.Cancel = true. Depending on what is currently displayed on the WizardPage, it could be correct to cancel the movement to the next or previous wizardPage.

The 4 others events (Finish, Help, Cancel and PageChanged) cannot be cancelled since we want direct action with those. For the Cancel event, it would be weird to cancel a cancel event.

2) The "_wizard" comes from the "x:Name" of my Wizard defined in XAML :
 <Grid>
      <xctk:Wizard x:Name="_wizard" 
                   FinishButtonClosesWindow="True">
         <xctk:WizardPage Title="Welcome to my Wizard"
                             Description="This Wizard will walk you though how to do something." />
         <xctk:WizardPage PageType="Interior"
                             Title="Page 1"
                             Description="This is the first page in the process." />
         <xctk:WizardPage PageType="Interior"
                             Title="Page 2"
                             Description="This is the second page in the process" />
         <xctk:WizardPage PageType="Interior"
                             Title="Last Page"
                             Description="This is the last page in the process"
                             CanFinish="True" />
      </xctk:Wizard>
</Grid>
 public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
      _wizard.Next += _wizard_Next;
    }

    private void _wizard_Next( object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e )
    {

    }
  }
If you really want to make everything in code-behind, here's a way :
 public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();

      var wizard = new Wizard();
      wizard.FinishButtonClosesWindow = true;
      wizard.Next += this.Wizard_Next;
      wizard.Items.Add( new WizardPage() { Title = "Welcome to my Wizard", Description = "This Wizard will walk you though how to do something." } );
      wizard.Items.Add( new WizardPage() { Title = "Page 1", Description = "This is the first page in the process.", PageType = WizardPageType.Interior } );
      wizard.Items.Add( new WizardPage() { Title = "Page 2", Description = "This is the second page in the process.", PageType = WizardPageType.Interior } );
      wizard.Items.Add( new WizardPage() { Title = "Last Page", Description = "This is the last page in the process.", PageType = WizardPageType.Interior, CanFinish = true } );

      this.Content = wizard;
    }

    private void Wizard_Next( object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e )
    {
    }
  }
Oct 21, 2015 at 9:03 AM
Hi again,

Thank you very much for your answer.

I have created a solution based on your first suggestion. A mixture of code behind and xaml since the point was for me to learn :-)

best regards
Gouzgounis.