Browse Source

Wizard: implemented rest of buttons. You can override button behaviors of Wizard on a WizardPage by WizardPage basis.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
20e6bf8faa
  1. 4
      ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Wizard/Views/HomeView.xaml
  2. 193
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/Wizard.cs
  3. 35
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/WizardPage.cs

4
ExtendedWPFToolkitSolution/Src/Samples/Modules/Samples.Modules.Wizard/Views/HomeView.xaml

@ -5,7 +5,7 @@
<Grid> <Grid>
<extToolkit:Wizard > <extToolkit:Wizard >
<extToolkit:WizardPage x:Name="page1" Title="Page 1 Title" <extToolkit:WizardPage x:Name="page1" Title="Page 1 Title"
Description="Page 1 Description"> Description="Page 1 Description" >
<Label Content="Page 1 content" /> <Label Content="Page 1 content" />
</extToolkit:WizardPage> </extToolkit:WizardPage>
<extToolkit:WizardPage x:Name="page2" Title="Page 2 Title" <extToolkit:WizardPage x:Name="page2" Title="Page 2 Title"
@ -15,7 +15,7 @@
<Label Content="Page 2 content" /> <Label Content="Page 2 content" />
</extToolkit:WizardPage> </extToolkit:WizardPage>
<extToolkit:WizardPage x:Name="page3" Title="Page 3 Title" <extToolkit:WizardPage x:Name="page3" Title="Page 3 Title"
Description="Page 3 Description"> Description="Page 3 Description" CanFinish="True">
<Label Content="Page 3 content" /> <Label Content="Page 3 content" />
</extToolkit:WizardPage> </extToolkit:WizardPage>
</extToolkit:Wizard> </extToolkit:Wizard>

193
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/Wizard.cs

@ -2,8 +2,6 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Data;
namespace Microsoft.Windows.Controls namespace Microsoft.Windows.Controls
{ {
@ -25,6 +23,20 @@ namespace Microsoft.Windows.Controls
set { SetValue(BackButtonVisibilityProperty, value); } set { SetValue(BackButtonVisibilityProperty, value); }
} }
public static readonly DependencyProperty CanCancelProperty = DependencyProperty.Register("CanCancel", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true));
public bool CanCancel
{
get { return (bool)GetValue(CanCancelProperty); }
set { SetValue(CanCancelProperty, value); }
}
public static readonly DependencyProperty CancelButtonClosesWindowProperty = DependencyProperty.Register("CancelButtonClosesWindow", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true));
public bool CancelButtonClosesWindow
{
get { return (bool)GetValue(CancelButtonClosesWindowProperty); }
set { SetValue(CancelButtonClosesWindowProperty, value); }
}
public static readonly DependencyProperty CancelButtonContentProperty = DependencyProperty.Register("CancelButtonContent", typeof(object), typeof(Wizard), new UIPropertyMetadata("Cancel")); public static readonly DependencyProperty CancelButtonContentProperty = DependencyProperty.Register("CancelButtonContent", typeof(object), typeof(Wizard), new UIPropertyMetadata("Cancel"));
public object CancelButtonContent public object CancelButtonContent
{ {
@ -39,6 +51,34 @@ namespace Microsoft.Windows.Controls
set { SetValue(CancelButtonVisibilityProperty, value); } set { SetValue(CancelButtonVisibilityProperty, value); }
} }
public static readonly DependencyProperty CanFinishProperty = DependencyProperty.Register("CanFinish", typeof(bool), typeof(Wizard), new UIPropertyMetadata(false));
public bool CanFinish
{
get { return (bool)GetValue(CanFinishProperty); }
set { SetValue(CanFinishProperty, value); }
}
public static readonly DependencyProperty CanHelpProperty = DependencyProperty.Register("CanHelp", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true));
public bool CanHelp
{
get { return (bool)GetValue(CanHelpProperty); }
set { SetValue(CanHelpProperty, value); }
}
public static readonly DependencyProperty CanSelectNextPageProperty = DependencyProperty.Register("CanSelectNextPage", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true));
public bool CanSelectNextPage
{
get { return (bool)GetValue(CanSelectNextPageProperty); }
set { SetValue(CanSelectNextPageProperty, value); }
}
public static readonly DependencyProperty CanSelectPreviousPageProperty = DependencyProperty.Register("CanSelectPreviousPage", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true));
public bool CanSelectPreviousPage
{
get { return (bool)GetValue(CanSelectPreviousPageProperty); }
set { SetValue(CanSelectPreviousPageProperty, value); }
}
#region CurrentPage #region CurrentPage
public static readonly DependencyProperty CurrentPageProperty = DependencyProperty.Register("CurrentPage", typeof(WizardPage), typeof(Wizard), new UIPropertyMetadata(null, OnCurrentPageChanged)); public static readonly DependencyProperty CurrentPageProperty = DependencyProperty.Register("CurrentPage", typeof(WizardPage), typeof(Wizard), new UIPropertyMetadata(null, OnCurrentPageChanged));
@ -62,6 +102,13 @@ namespace Microsoft.Windows.Controls
#endregion //CurrentPage #endregion //CurrentPage
public static readonly DependencyProperty FinishButtonClosesWindowProperty = DependencyProperty.Register("FinishButtonClosesWindow", typeof(bool), typeof(Wizard), new UIPropertyMetadata(true));
public bool FinishButtonClosesWindow
{
get { return (bool)GetValue(FinishButtonClosesWindowProperty); }
set { SetValue(FinishButtonClosesWindowProperty, value); }
}
public static readonly DependencyProperty FinishButtonContentProperty = DependencyProperty.Register("FinishButtonContent", typeof(object), typeof(Wizard), new UIPropertyMetadata("Finish")); public static readonly DependencyProperty FinishButtonContentProperty = DependencyProperty.Register("FinishButtonContent", typeof(object), typeof(Wizard), new UIPropertyMetadata("Finish"));
public object FinishButtonContent public object FinishButtonContent
{ {
@ -115,11 +162,11 @@ namespace Microsoft.Windows.Controls
public Wizard() public Wizard()
{ {
CommandBindings.Add(new CommandBinding(WizardCommands.Cancel, CancelWizard, CanCancelWizard)); CommandBindings.Add(new CommandBinding(WizardCommands.Cancel, ExecuteCancelWizard, CanExecuteCancelWizard));
CommandBindings.Add(new CommandBinding(WizardCommands.Finish, FinishWizard, CanFinishWizard)); CommandBindings.Add(new CommandBinding(WizardCommands.Finish, ExecuteFinishWizard, CanExecuteFinishWizard));
CommandBindings.Add(new CommandBinding(WizardCommands.Help, RequestHelp, CanRequestHelp)); CommandBindings.Add(new CommandBinding(WizardCommands.Help, ExecuteRequestHelp, CanExecuteRequestHelp));
CommandBindings.Add(new CommandBinding(WizardCommands.NextPage, SelectNextPage, CanSelectNextPage)); CommandBindings.Add(new CommandBinding(WizardCommands.NextPage, ExecuteSelectNextPage, CanExecuteSelectNextPage));
CommandBindings.Add(new CommandBinding(WizardCommands.PreviousPage, SelectPreviousPage, CanSelectPreviousPage)); CommandBindings.Add(new CommandBinding(WizardCommands.PreviousPage, ExecuteSelectPreviousPage, CanExecuteSelectPreviousPage));
} }
#endregion //Constructors #endregion //Constructors
@ -148,37 +195,61 @@ namespace Microsoft.Windows.Controls
#region Commands #region Commands
private void CancelWizard(object sender, ExecutedRoutedEventArgs e) private void ExecuteCancelWizard(object sender, ExecutedRoutedEventArgs e)
{ {
RaiseRoutedEvent(Wizard.CancelEvent); RaiseRoutedEvent(Wizard.CancelEvent);
if (CancelButtonClosesWindow)
CloseParentWindow(false);
} }
private void CanCancelWizard(object sender, CanExecuteRoutedEventArgs e) private void CanExecuteCancelWizard(object sender, CanExecuteRoutedEventArgs e)
{ {
e.CanExecute = false; if (CurrentPage != null)
{
if (CurrentPage.CanCancel.HasValue)
e.CanExecute = CurrentPage.CanCancel.Value;
else
e.CanExecute = CanCancel;
}
} }
private void FinishWizard(object sender, ExecutedRoutedEventArgs e) private void ExecuteFinishWizard(object sender, ExecutedRoutedEventArgs e)
{ {
RaiseRoutedEvent(Wizard.FinishEvent); RaiseRoutedEvent(Wizard.FinishEvent);
if (FinishButtonClosesWindow)
CloseParentWindow(true);
} }
private void CanFinishWizard(object sender, CanExecuteRoutedEventArgs e) private void CanExecuteFinishWizard(object sender, CanExecuteRoutedEventArgs e)
{ {
e.CanExecute = false; if (CurrentPage != null)
{
if (CurrentPage.CanFinish.HasValue)
e.CanExecute = CurrentPage.CanFinish.Value;
else
e.CanExecute = CanFinish;
}
} }
private void RequestHelp(object sender, ExecutedRoutedEventArgs e) private void ExecuteRequestHelp(object sender, ExecutedRoutedEventArgs e)
{ {
RaiseRoutedEvent(Wizard.HelpEvent); RaiseRoutedEvent(Wizard.HelpEvent);
} }
private void CanRequestHelp(object sender, CanExecuteRoutedEventArgs e) private void CanExecuteRequestHelp(object sender, CanExecuteRoutedEventArgs e)
{ {
e.CanExecute = false; if (CurrentPage != null)
{
if (CurrentPage.CanHelp.HasValue)
e.CanExecute = CurrentPage.CanHelp.Value;
else
e.CanExecute = CanHelp;
}
} }
private void SelectNextPage(object sender, ExecutedRoutedEventArgs e) private void ExecuteSelectNextPage(object sender, ExecutedRoutedEventArgs e)
{ {
WizardPage nextPage = null; WizardPage nextPage = null;
@ -200,23 +271,21 @@ namespace Microsoft.Windows.Controls
CurrentPage = nextPage; CurrentPage = nextPage;
} }
private void CanSelectNextPage(object sender, CanExecuteRoutedEventArgs e) private void CanExecuteSelectNextPage(object sender, CanExecuteRoutedEventArgs e)
{ {
if (CurrentPage != null) if (CurrentPage != null)
{ {
if (CurrentPage.NextPage != null) if (CurrentPage.CanSelectNextPage.HasValue) //check to see if page has overriden default behavior
e.CanExecute = true;
else
{ {
var currentIndex = Items.IndexOf(CurrentPage); if (CurrentPage.CanSelectNextPage.Value)
var nextPageIndex = currentIndex + 1; e.CanExecute = NextPageExists();
if (nextPageIndex < Items.Count)
e.CanExecute = true;
} }
else if (CanSelectNextPage)
e.CanExecute = NextPageExists();
} }
} }
private void SelectPreviousPage(object sender, ExecutedRoutedEventArgs e) private void ExecuteSelectPreviousPage(object sender, ExecutedRoutedEventArgs e)
{ {
WizardPage previousPage = null; WizardPage previousPage = null;
@ -238,19 +307,17 @@ namespace Microsoft.Windows.Controls
CurrentPage = previousPage; CurrentPage = previousPage;
} }
private void CanSelectPreviousPage(object sender, CanExecuteRoutedEventArgs e) private void CanExecuteSelectPreviousPage(object sender, CanExecuteRoutedEventArgs e)
{ {
if (CurrentPage != null) if (CurrentPage != null)
{ {
if (CurrentPage.PreviousPage != null) if (CurrentPage.CanSelectPreviousPage.HasValue) //check to see if page has overriden default behavior
e.CanExecute = true;
else
{ {
var currentIndex = Items.IndexOf(CurrentPage); if (CurrentPage.CanSelectPreviousPage.Value)
var previousPageIndex = currentIndex - 1; e.CanExecute = PreviousPageExists();
if (previousPageIndex > 0 && previousPageIndex < Items.Count)
e.CanExecute = true;
} }
else if (CanSelectPreviousPage)
e.CanExecute = PreviousPageExists();
} }
} }
@ -290,6 +357,64 @@ namespace Microsoft.Windows.Controls
#region Methods #region Methods
private void CloseParentWindow(bool dialogResult)
{
Window window = Window.GetWindow(this);
if (window != null)
{
try
{
window.DialogResult = dialogResult;
}
catch (InvalidOperationException)
{
//DialogResult can be set only after Window is created and shown as dialog.
//So if the Window is not shown as a dialog then an exception would occur. Therefore
//let's just swallow the exception
}
finally
{
window.Close();
}
}
}
private bool NextPageExists()
{
bool exists = false;
if (CurrentPage.NextPage != null) //check to see if a next page has been specified
exists = true;
else
{
//lets use an index to find the next page
var currentIndex = Items.IndexOf(CurrentPage);
var nextPageIndex = currentIndex + 1;
if (nextPageIndex < Items.Count)
exists = true;
}
return exists;
}
private bool PreviousPageExists()
{
bool exists = false;
if (CurrentPage.PreviousPage != null) //check to see if a previous page has been specified
exists = true;
else
{
//lets use an index to find the next page
var currentIndex = Items.IndexOf(CurrentPage);
var previousPageIndex = currentIndex - 1;
if (previousPageIndex > 0 && previousPageIndex < Items.Count)
exists = true;
}
return exists;
}
private void RaiseRoutedEvent(RoutedEvent routedEvent) private void RaiseRoutedEvent(RoutedEvent routedEvent)
{ {
RoutedEventArgs newEventArgs = new RoutedEventArgs(routedEvent, this); RoutedEventArgs newEventArgs = new RoutedEventArgs(routedEvent, this);

35
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Wizard/Implementation/WizardPage.cs

@ -15,6 +15,13 @@ namespace Microsoft.Windows.Controls
set { SetValue(BackButtonVisibilityProperty, value); } set { SetValue(BackButtonVisibilityProperty, value); }
} }
public static readonly DependencyProperty CanCancelProperty = DependencyProperty.Register("CanCancel", typeof(bool?), typeof(WizardPage), new UIPropertyMetadata(null));
public bool? CanCancel
{
get { return (bool?)GetValue(CanCancelProperty); }
set { SetValue(CanCancelProperty, value); }
}
public static readonly DependencyProperty CancelButtonVisibilityProperty = DependencyProperty.Register("CancelButtonVisibility", typeof(WizardPageButtonVisibility), typeof(WizardPage), new UIPropertyMetadata(WizardPageButtonVisibility.Inherit)); public static readonly DependencyProperty CancelButtonVisibilityProperty = DependencyProperty.Register("CancelButtonVisibility", typeof(WizardPageButtonVisibility), typeof(WizardPage), new UIPropertyMetadata(WizardPageButtonVisibility.Inherit));
public WizardPageButtonVisibility CancelButtonVisibility public WizardPageButtonVisibility CancelButtonVisibility
{ {
@ -22,6 +29,34 @@ namespace Microsoft.Windows.Controls
set { SetValue(CancelButtonVisibilityProperty, value); } set { SetValue(CancelButtonVisibilityProperty, value); }
} }
public static readonly DependencyProperty CanFinishProperty = DependencyProperty.Register("CanFinish", typeof(bool?), typeof(WizardPage), new UIPropertyMetadata(null));
public bool? CanFinish
{
get { return (bool?)GetValue(CanFinishProperty); }
set { SetValue(CanFinishProperty, value); }
}
public static readonly DependencyProperty CanHelpProperty = DependencyProperty.Register("CanHelp", typeof(bool?), typeof(WizardPage), new UIPropertyMetadata(null));
public bool? CanHelp
{
get { return (bool?)GetValue(CanHelpProperty); }
set { SetValue(CanHelpProperty, value); }
}
public static readonly DependencyProperty CanSelectNextPageProperty = DependencyProperty.Register("CanSelectNextPage", typeof(bool?), typeof(WizardPage), new UIPropertyMetadata(null));
public bool? CanSelectNextPage
{
get { return (bool?)GetValue(CanSelectNextPageProperty); }
set { SetValue(CanSelectNextPageProperty, value); }
}
public static readonly DependencyProperty CanSelectPreviousPageProperty = DependencyProperty.Register("CanSelectPreviousPage", typeof(bool?), typeof(WizardPage), new UIPropertyMetadata(null));
public bool? CanSelectPreviousPage
{
get { return (bool?)GetValue(CanSelectPreviousPageProperty); }
set { SetValue(CanSelectPreviousPageProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(WizardPage)); public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register("Description", typeof(string), typeof(WizardPage));
public string Description public string Description
{ {

Loading…
Cancel
Save