@ -2,11 +2,110 @@
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Input ;
using System.Windows.Markup ;
using System.Windows.Data ;
namespace Microsoft.Windows.Controls
{
public class Wizard : ItemsControl
{
#region Properties
public static readonly DependencyProperty BackButtonContentProperty = DependencyProperty . Register ( "BackButtonContent" , typeof ( object ) , typeof ( Wizard ) , new UIPropertyMetadata ( "Back" ) ) ;
public object BackButtonContent
{
get { return ( object ) GetValue ( BackButtonContentProperty ) ; }
set { SetValue ( BackButtonContentProperty , value ) ; }
}
public static readonly DependencyProperty BackButtonVisibilityProperty = DependencyProperty . Register ( "BackButtonVisibility" , typeof ( Visibility ) , typeof ( Wizard ) , new UIPropertyMetadata ( Visibility . Visible ) ) ;
public Visibility BackButtonVisibility
{
get { return ( Visibility ) GetValue ( BackButtonVisibilityProperty ) ; }
set { SetValue ( BackButtonVisibilityProperty , value ) ; }
}
public static readonly DependencyProperty CancelButtonContentProperty = DependencyProperty . Register ( "CancelButtonContent" , typeof ( object ) , typeof ( Wizard ) , new UIPropertyMetadata ( "Cancel" ) ) ;
public object CancelButtonContent
{
get { return ( object ) GetValue ( CancelButtonContentProperty ) ; }
set { SetValue ( CancelButtonContentProperty , value ) ; }
}
public static readonly DependencyProperty CancelButtonVisibilityProperty = DependencyProperty . Register ( "CancelButtonVisibility" , typeof ( Visibility ) , typeof ( Wizard ) , new UIPropertyMetadata ( Visibility . Visible ) ) ;
public Visibility CancelButtonVisibility
{
get { return ( Visibility ) GetValue ( CancelButtonVisibilityProperty ) ; }
set { SetValue ( CancelButtonVisibilityProperty , value ) ; }
}
#region CurrentPage
public static readonly DependencyProperty CurrentPageProperty = DependencyProperty . Register ( "CurrentPage" , typeof ( WizardPage ) , typeof ( Wizard ) , new UIPropertyMetadata ( null , OnCurrentPageChanged ) ) ;
public WizardPage CurrentPage
{
get { return ( WizardPage ) GetValue ( CurrentPageProperty ) ; }
set { SetValue ( CurrentPageProperty , value ) ; }
}
private static void OnCurrentPageChanged ( DependencyObject o , DependencyPropertyChangedEventArgs e )
{
Wizard wizard = o as Wizard ;
if ( wizard ! = null )
wizard . OnCurrentPageChanged ( ( WizardPage ) e . OldValue , ( WizardPage ) e . NewValue ) ;
}
protected virtual void OnCurrentPageChanged ( WizardPage oldValue , WizardPage newValue )
{
RaiseRoutedEvent ( Wizard . PageChangedEvent ) ;
}
#endregion //CurrentPage
public static readonly DependencyProperty FinishButtonContentProperty = DependencyProperty . Register ( "FinishButtonContent" , typeof ( object ) , typeof ( Wizard ) , new UIPropertyMetadata ( "Finish" ) ) ;
public object FinishButtonContent
{
get { return ( object ) GetValue ( FinishButtonContentProperty ) ; }
set { SetValue ( FinishButtonContentProperty , value ) ; }
}
public static readonly DependencyProperty FinishButtonVisibilityProperty = DependencyProperty . Register ( "FinishButtonVisibility" , typeof ( Visibility ) , typeof ( Wizard ) , new UIPropertyMetadata ( Visibility . Visible ) ) ;
public Visibility FinishButtonVisibility
{
get { return ( Visibility ) GetValue ( FinishButtonVisibilityProperty ) ; }
set { SetValue ( FinishButtonVisibilityProperty , value ) ; }
}
public static readonly DependencyProperty HelpButtonContentProperty = DependencyProperty . Register ( "HelpButtonContent" , typeof ( object ) , typeof ( Wizard ) , new UIPropertyMetadata ( "Help" ) ) ;
public object HelpButtonContent
{
get { return ( object ) GetValue ( HelpButtonContentProperty ) ; }
set { SetValue ( HelpButtonContentProperty , value ) ; }
}
public static readonly DependencyProperty HelpButtonVisibilityProperty = DependencyProperty . Register ( "HelpButtonVisibility" , typeof ( Visibility ) , typeof ( Wizard ) , new UIPropertyMetadata ( Visibility . Visible ) ) ;
public Visibility HelpButtonVisibility
{
get { return ( Visibility ) GetValue ( HelpButtonVisibilityProperty ) ; }
set { SetValue ( HelpButtonVisibilityProperty , value ) ; }
}
public static readonly DependencyProperty NextButtonContentProperty = DependencyProperty . Register ( "NextButtonContent" , typeof ( object ) , typeof ( Wizard ) , new UIPropertyMetadata ( "Next" ) ) ;
public object NextButtonContent
{
get { return ( object ) GetValue ( NextButtonContentProperty ) ; }
set { SetValue ( NextButtonContentProperty , value ) ; }
}
public static readonly DependencyProperty NextButtonVisibilityProperty = DependencyProperty . Register ( "NextButtonVisibility" , typeof ( Visibility ) , typeof ( Wizard ) , new UIPropertyMetadata ( Visibility . Visible ) ) ;
public Visibility NextButtonVisibility
{
get { return ( Visibility ) GetValue ( NextButtonVisibilityProperty ) ; }
set { SetValue ( NextButtonVisibilityProperty , value ) ; }
}
#endregion //Properties
#region Constructors
static Wizard ( )
@ -16,12 +115,11 @@ namespace Microsoft.Windows.Controls
public Wizard ( )
{
CommandBindings . Add ( new CommandBinding ( WizardCommands . Cancel , Cancel , CanCancel ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . Finish , Finish , CanFinish ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . Help , Help , CanHelp ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . Cancel , CancelWizard , CanCancelWizard ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . Finish , FinishWizard , CanFinishWizard ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . Help , Request Help, CanRequest Help ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . NextPage , SelectNextPage , CanSelectNextPage ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . PreviousPage , SelectPreviousPage , CanSelectPreviousPage ) ) ;
CommandBindings . Add ( new CommandBinding ( WizardCommands . SelectPage , SelectPage , CanSelectPage ) ) ;
}
#endregion //Constructors
@ -38,70 +136,166 @@ namespace Microsoft.Windows.Controls
return ( item is WizardPage ) ;
}
protected override void OnInitialized ( EventArgs e )
{
base . OnInitialized ( e ) ;
if ( Items . Count > 0 & & CurrentPage = = null )
CurrentPage = Items [ 0 ] as WizardPage ;
}
#endregion //Base Class Overrides
#region Commands
private void Cancel ( object sender , ExecutedRoutedEventArgs e )
private void CancelWizard ( object sender , ExecutedRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
RaiseRoutedEvent ( Wizard . CancelEvent ) ;
}
private void CanCancel ( object sender , CanExecuteRoutedEventArgs e )
private void CanCancelWizard ( object sender , CanExecuteRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
e . CanExecute = false ;
}
private void Finish ( object sender , ExecutedRoutedEventArgs e )
private void FinishWizard ( object sender , ExecutedRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
RaiseRoutedEvent ( Wizard . FinishEvent ) ;
}
private void CanFinish ( object sender , CanExecuteRoutedEventArgs e )
private void CanFinishWizard ( object sender , CanExecuteRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
e . CanExecute = false ;
}
private void Help ( object sender , ExecutedRoutedEventArgs e )
private void Request Help( object sender , ExecutedRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
RaiseRoutedEvent ( Wizard . HelpEvent ) ;
}
private void CanHelp ( object sender , CanExecuteRoutedEventArgs e )
private void CanRequest Help ( object sender , CanExecuteRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
e . CanExecute = false ;
}
private void SelectNextPage ( object sender , ExecutedRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
WizardPage nextPage = null ;
if ( CurrentPage ! = null )
{
//check next page
if ( CurrentPage . NextPage ! = null )
nextPage = CurrentPage . NextPage ;
else
{
//no next page defined use index
var currentIndex = Items . IndexOf ( CurrentPage ) ;
var nextPageIndex = currentIndex + 1 ;
if ( nextPageIndex < Items . Count )
nextPage = Items [ nextPageIndex ] as WizardPage ;
}
}
CurrentPage = nextPage ;
}
private void CanSelectNextPage ( object sender , CanExecuteRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
if ( CurrentPage ! = null )
{
if ( CurrentPage . NextPage ! = null )
e . CanExecute = true ;
else
{
var currentIndex = Items . IndexOf ( CurrentPage ) ;
var nextPageIndex = currentIndex + 1 ;
if ( nextPageIndex < Items . Count )
e . CanExecute = true ;
}
}
}
private void SelectPreviousPage ( object sender , ExecutedRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
WizardPage previousPage = null ;
if ( CurrentPage ! = null )
{
//check previous page
if ( CurrentPage . PreviousPage ! = null )
previousPage = CurrentPage . PreviousPage ;
else
{
//no previous page defined so use index
var currentIndex = Items . IndexOf ( CurrentPage ) ;
var previousPageIndex = currentIndex - 1 ;
if ( previousPageIndex > 0 & & previousPageIndex < Items . Count )
previousPage = Items [ previousPageIndex ] as WizardPage ;
}
}
CurrentPage = previousPage ;
}
private void CanSelectPreviousPage ( object sender , CanExecuteRoutedEventArgs e )
{
throw new NotImplementedException ( ) ;
if ( CurrentPage ! = null )
{
if ( CurrentPage . PreviousPage ! = null )
e . CanExecute = true ;
else
{
var currentIndex = Items . IndexOf ( CurrentPage ) ;
var previousPageIndex = currentIndex - 1 ;
if ( previousPageIndex > 0 & & previousPageIndex < Items . Count )
e . CanExecute = true ;
}
}
}
#endregion //Commands
#region Events
public static readonly RoutedEvent CancelEvent = EventManager . RegisterRoutedEvent ( "Cancel" , RoutingStrategy . Bubble , typeof ( EventHandler ) , typeof ( Wizard ) ) ;
public event RoutedEventHandler Cancel
{
add { AddHandler ( CancelEvent , value ) ; }
remove { RemoveHandler ( CancelEvent , value ) ; }
}
private void SelectPage ( object sender , ExecutedRoutedEventArgs e )
public static readonly RoutedEvent PageChangedEvent = EventManager . RegisterRoutedEvent ( "PageChanged" , RoutingStrategy . Bubble , typeof ( EventHandler ) , typeof ( Wizard ) ) ;
public event RoutedEventHandler PageChanged
{
throw new NotImplementedException ( ) ;
add { AddHandler ( PageChangedEvent , value ) ; }
remove { RemoveHandler ( PageChangedEvent , value ) ; }
}
private void CanSelectPage ( object sender , CanExecuteRoutedEventArgs e )
public static readonly RoutedEvent FinishEvent = EventManager . RegisterRoutedEvent ( "Finish" , RoutingStrategy . Bubble , typeof ( EventHandler ) , typeof ( Wizard ) ) ;
public event RoutedEventHandler Finish
{
throw new NotImplementedException ( ) ;
add { AddHandler ( FinishEvent , value ) ; }
remove { RemoveHandler ( FinishEvent , value ) ; }
}
#endregion //Commands
public static readonly RoutedEvent HelpEvent = EventManager . RegisterRoutedEvent ( "Help" , RoutingStrategy . Bubble , typeof ( EventHandler ) , typeof ( Wizard ) ) ;
public event RoutedEventHandler Help
{
add { AddHandler ( HelpEvent , value ) ; }
remove { RemoveHandler ( HelpEvent , value ) ; }
}
#endregion //Events
#region Methods
private void RaiseRoutedEvent ( RoutedEvent routedEvent )
{
RoutedEventArgs newEventArgs = new RoutedEventArgs ( routedEvent , this ) ;
base . RaiseEvent ( newEventArgs ) ;
}
#endregion //Methods
}
}
}