1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
7
using System.Collections.Generic;
11
using System.Windows.Controls;
12
using System.Windows.Data;
13
using System.Windows.Documents;
14
using System.Windows.Input;
15
using System.Windows.Media;
16
using System.Windows.Media.Imaging;
17
using System.Windows.Shapes;
18
using System.Collections.ObjectModel;
19
using ICSharpCode.Data.Core.UI.UserControls;
20
using System.ComponentModel;
21
using System.Collections.Specialized;
25
namespace ICSharpCode.Data.Core.UI.Windows
28
/// Interaction logic for WizardWindow.xaml
30
public partial class WizardWindowInnards : UserControl, INotifyPropertyChanged
34
internal static readonly DependencyProperty IsReadyForNextStepProperty =
35
DependencyProperty.Register("IsReadyForNextStep", typeof(bool), typeof(WizardWindowInnards), new FrameworkPropertyMetadata(false, IsReadyForNextStep_Changed));
36
private WizardWindow _wizardWindow = null;
37
private ObservableCollection<WizardUserControl> _wizardUserControls = new ObservableCollection<WizardUserControl>();
38
private WizardErrorUserControl _wizardErrorUserControl = null;
39
private WizardUserControl _currentWizardUserControl = null;
40
private int _currentIndex = 0;
41
private int _previousIndex = 0;
48
/// Returns the ObservableCollection of WizardUserControls, which are displayed in this WizardWindow.
50
public ObservableCollection<WizardUserControl> WizardUserControls
52
get { return _wizardUserControls; }
56
/// Gets or sets the current WizardWindows' user control for displaying errors.
58
public WizardErrorUserControl WizardErrorUserControl
60
get { return _wizardErrorUserControl; }
61
set { _wizardErrorUserControl = value; }
65
/// Returns the current WizardUserControls index of the WizardWindow.
67
public int CurrentIndex
69
get { return _currentIndex; }
72
_previousIndex = _currentIndex;
73
_currentIndex = value;
74
_currentWizardUserControl = null;
75
OnPropertyChanged("CurrentIndex");
76
OnPropertyChanged("CurrentWizardUserControl");
81
/// Returns the current WizardUserControl of the WizardWindow.
83
public WizardUserControl CurrentWizardUserControl
87
if (_currentWizardUserControl != null)
88
return _currentWizardUserControl;
92
if (_currentIndex == -1)
94
_currentWizardUserControl = _wizardErrorUserControl;
98
_currentWizardUserControl = _wizardUserControls.FirstOrDefault(wuc => wuc.Index == _currentIndex);
99
BindingBase binding = new Binding("IsReadyForNextStep") { Source = _currentWizardUserControl };
100
SetBinding(WizardWindowInnards.IsReadyForNextStepProperty, binding);
103
if (_currentWizardUserControl != null)
105
if (_currentIndex != -1 && _currentIndex - 1 == _previousIndex)
106
_currentWizardUserControl.Activate(true);
108
_currentWizardUserControl.Activate(false);
110
ToggleEnabledButtons();
113
return _currentWizardUserControl;
123
/// Initizales the WizardWindow.
125
public WizardWindowInnards(WizardWindow wizardWindow)
127
InitializeComponent();
128
_wizardWindow = wizardWindow;
129
_wizardUserControls.CollectionChanged += new NotifyCollectionChangedEventHandler(WizardUserControls_CollectionChanged);
130
DataContext = wizardWindow;
137
private void ToggleEnabledButtons()
142
if (_currentIndex == 0)
144
btnPrevious.IsEnabled = false;
148
btnPrevious.IsEnabled = true;
151
if (_currentIndex == -1 || _currentIndex == _wizardUserControls.Count - 1)
153
btnNext.IsEnabled = false;
157
if (CurrentWizardUserControl.IsReadyForNextStep)
158
btnNext.IsEnabled = true;
160
btnNext.IsEnabled = false;
163
if (CurrentWizardUserControl.CanFinish)
165
if (CurrentWizardUserControl.IsReadyForNextStep)
166
btnFinish.IsEnabled = true;
169
btnFinish.IsEnabled = false;
174
#region Event handlers
176
private static void IsReadyForNextStep_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
178
WizardWindowInnards wizardWindowInnards = d as WizardWindowInnards;
179
wizardWindowInnards.ToggleEnabledButtons();
182
private void WizardUserControls_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
184
OnPropertyChanged("CurrentWizardUserControl");
187
private void btnPrevious_Click(object sender, RoutedEventArgs e)
189
if (CurrentIndex == 0)
191
else if (CurrentIndex == -1)
193
CurrentIndex = _wizardErrorUserControl.PreviousIndex;
201
private void btnNext_Click(object sender, RoutedEventArgs e)
203
if (CurrentIndex == _wizardUserControls.Count - 1)
211
private void btnFinish_Click(object sender, RoutedEventArgs e)
215
_wizardWindow.OnFinished();
219
if (_wizardErrorUserControl != null)
221
_wizardErrorUserControl.Exception = ex;
222
_wizardErrorUserControl.PreviousIndex = _currentIndex;
233
_wizardWindow.DialogResult = true;
234
_wizardWindow.Close();
237
private void btnCancel_Click(object sender, RoutedEventArgs e)
239
_wizardWindow.DialogResult = false;
240
_wizardWindow.Close();
245
#region INotifyPropertyChanged
247
public event PropertyChangedEventHandler PropertyChanged;
249
protected void OnPropertyChanged(string property)
251
if (PropertyChanged != null)
253
PropertyChanged(this, new PropertyChangedEventArgs(property));