/// <summary> /// Raises the <see cref="SelectingEvent"/> event. /// </summary> /// <param name="e">A <see cref="WizardSelectedPageChangeEventArgs"/> that contains the event data.</param> protected override void OnUnselecting(WizardSelectedPageChangeEventArgs e) { // Call the base method base.OnUnselecting(e); if (!e.Handled) { bool isForwardProgress = ((e.SelectionFlags & WizardPageSelectionFlags.ForwardProgress) == WizardPageSelectionFlags.ForwardProgress); bool isBackwardProgress = ((e.SelectionFlags & WizardPageSelectionFlags.BackwardProgress) == WizardPageSelectionFlags.BackwardProgress); ItemStore store = (ItemStore)this.Wizard.Tag; if ( ((isForwardProgress) && (store.CurrentIndex < store.Items.Count - 1)) || ((isBackwardProgress) && (store.CurrentIndex > 0)) ) { // Cancel the page change e.Handled = true; e.Cancel = true; // Update the current item index and reinit the page store.CurrentIndex = store.CurrentIndex + (isForwardProgress ? 1 : -1); this.InitializePage(); } } }
/// <summary> /// Raises the <see cref="UnselectingEvent"/> event. /// </summary> /// <param name="e">A <see cref="WizardSelectedPageChangeEventArgs"/> that contains the event data.</param> protected override void OnUnselecting(WizardSelectedPageChangeEventArgs e) { // Call the base method base.OnUnselecting(e); // Get the repeat count TextBox repeatCountTextbox = (TextBox)this.FindName("PART_RepeatCountTextBox"); if (repeatCountTextbox != null) { int repeatCount; if ((int.TryParse(repeatCountTextbox.Text, out repeatCount)) && (repeatCount > 0) && (repeatCount <= 10)) { // Place an ItemStore in the Wizard's Tag ItemStore store = (ItemStore)this.Wizard.Tag; if ((store == null) || (store.Items.Count != repeatCount)) { store = new ItemStore(); for (int index = 0; index < repeatCount; index++) { Item item = new Item(); item.Index = index + 1; store.Items.Add(item); } this.Wizard.Tag = store; } return; } MessageBox.Show("Please enter a number between 1 and 10."); } e.Handled = true; e.Cancel = true; }
/// <summary> /// Initializes the page. /// </summary> private void InitializePage() { ItemStore store = (ItemStore)this.Wizard.Tag; // Update the caption and content of the page (content will be the item being edited) this.Caption = String.Format("Item #{0} Details", store.CurrentIndex + 1); this.Content = store.Items[store.CurrentIndex]; }