- goalbook.zip
- GoalBook
- Dependencies
- CAG WPF 2
- Microsoft.Practices.Composite.dll
- Microsoft.Practices.Composite.Presentation.dll
- Microsoft.Practices.Composite.UnityExtensions.dll
- Microsoft.Practices.ObjectBuilder2.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
- vssver2.scc
- CSLA
- Csla.dll
- Csla.XmlSerializers.dll
- vssver2.scc
- Infragistics
- Infragistics3.Wpf.DataPresenter.v9.1.Express.dll
- Infragistics3.Wpf.Editors.v9.1.Express.dll
- Infragistics3.Wpf.v9.1.Express.dll
- vssver2.scc
- WPFToolkit
- vssver2.scc
- WPFToolkit.dll
- GoalBook.Controls
- GoalBook.Goals
- GoalBook.Infrastructure
- GoalBook.Notes
- GoalBook.Public
- GoalBook.Shell
- App.ico
- App.xaml
- App.xaml.cs
- Bootstrapper.cs
- Commands
- GoalBook.Shell.csproj
- GoalBook.Shell.csproj.user
- Journal.ico
- Journal48.ico
- Misc
- Modules
- Properties
- Resources
- arrow_refresh.png
- arrow_undo.png
- checked.gif
- cross.png
- disk.png
- email.png
- erase.png
- error.png
- exclamation.png
- flag_red.png
- group.png
- help.png
- information.png
- magnifier.png
- page_red.png
- pencil.png
- printer.png
- user.png
- vssver2.scc
- Wave.jpg
- world.png
- world_link.png
- Services
- Splash.png
- Views
- vssver2.scc
- Windows
- GoalBook.sln
- GoalBook.snk
- GoalBook.Synchronisation
- GoalBook.Tasks
- License.txt
- ReadMe.txt
- SolutionInfo.cs
- vssver2.scc
|
//===============================================================================
// Goal Book.
// Copyright © 2009 Mark Brownsword.
//===============================================================================
#region Using Statements
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
#endregion
namespace GoalBook.Shell.Windows
{
/// <summary>
/// Interaction logic for Dialog.xaml
/// </summary>
public partial class Dialog : Window
{
#region Constructor
/// <summary>
/// Initializes a new instance of <see cref="ViewDialog"/>
/// </summary>
public Dialog()
{
InitializeComponent();
}
#endregion
#region Events
/// <summary>
/// Gets fired when the dialog needs to be validated.
/// </summary>
public event EventHandler<CancelEventArgs> ValidateDialog;
/// <summary>
/// Gets fired before the dialog closes.
/// </summary>
public event EventHandler<CancelEventArgs> CanCloseDialog;
#endregion
#region Private Members
/// <summary>
/// On Can Close Dialog.
/// </summary>
/// <returns>True when Can Close Dialog</returns>
private bool OnCanCloseDialog()
{
EventHandler<CancelEventArgs> canCloseDialog = CanCloseDialog;
bool cancelled = false;
if (canCloseDialog != null)
{
CancelEventArgs args = new CancelEventArgs();
canCloseDialog(this, args);
cancelled = args.Cancel;
}
return !cancelled;
}
/// <summary>
/// Do Event. Validate form.
/// </summary>
/// <returns>True if valid</returns>
private bool OnValidate()
{
EventHandler<CancelEventArgs> validateDialog = ValidateDialog;
bool cancelled = false;
if (validateDialog != null)
{
CancelEventArgs args = new CancelEventArgs();
validateDialog(this, args);
cancelled = args.Cancel;
}
return !cancelled;
}
/// <summary>
/// Close Dialog with specified result.
/// </summary>
/// <param name="result">result parameter</param>
private void CloseDialog(bool? result)
{
this.IsCancelled = result == null;
this.DialogResult = result;
this.Close();
}
#endregion
#region Event handlers
/// <summary>
/// Handle Window_Loaded event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">RoutedEventArgs parameter</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
IsCancelled = true;
IsDirty = false;
}
/// <summary>
/// Handle ButtonAccept_PreviewKeyUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">KeyEventArgs parameter</param>
private void ButtonAccept_PreviewKeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
if (OnValidate())
{
e.Handled = true;
CloseDialog(true);
}
}
}
/// <summary>
/// Handle ButtonAccept_PreviewMouseLeftButtonUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">MouseButtonEventArgs parameter</param>
private void ButtonAccept_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (OnValidate())
{
e.Handled = true;
CloseDialog(true);
}
}
/// <summary>
/// Handle ButtonReject_PreviewKeyUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">KeyEventArgs parameter</param>
private void ButtonReject_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
e.Handled = true;
CloseDialog(false);
}
}
/// <summary>
/// Handle ButtonReject_PreviewMouseLeftButtonUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">MouseButtonEventArgs parameter</param>
private void ButtonReject_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
CloseDialog(false);
}
/// <summary>
/// Handle ButtonCancel_PreviewKeyUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">KeyEventArgs parameter</param>
private void ButtonCancel_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
e.Handled = true;
CloseDialog(null);
}
}
/// <summary>
/// Handle ButtonCancel_PreviewMouseLeftButtonUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">MouseButtonEventArgs parameter</param>
private void ButtonCancel_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
CloseDialog(null);
}
/// <summary>
/// Handle Window_PreviewKeyUp event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">KeyEventArgs parameter</param>
private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
CloseDialog(null);
}
}
/// <summary>
/// Handle Window_Closing event.
/// </summary>
/// <param name="sender">sender parameter</param>
/// <param name="e">CancelEventArgs parameter</param>
private void Window_Closing(object sender, CancelEventArgs e)
{
if (this.IsCancelled && this.IsDirty)
{
e.Cancel = !OnCanCloseDialog();
}
}
#endregion
#region Properties
/// <summary>
/// Reference to ButtonPanelVisibility. Using a DependencyProperty as the backing store for
/// ButtonPanelVisibility. This enables animation, styling, binding, etc...
/// </summary>
public Visibility ButtonPanelVisibility
{
get { return (Visibility)GetValue(ButtonPanelVisibilityProperty); }
set { SetValue(ButtonPanelVisibilityProperty, value); }
}
public static readonly DependencyProperty ButtonPanelVisibilityProperty = DependencyProperty.Register("ButtonPanelVisibility",
typeof(Visibility), typeof(Dialog), new UIPropertyMetadata(Visibility.Visible));
/// <summary>
/// Gets or sets the view to show in the dialog
/// </summary>
public DependencyObject View
{
get { return (DependencyObject)GetValue(ViewProperty); }
set { SetValue(ViewProperty, value); }
}
public static readonly DependencyProperty ViewProperty = DependencyProperty.Register("View",
typeof(DependencyObject), typeof(Dialog), new UIPropertyMetadata(null));
/// <summary>
/// Gets value of IsCancelled property.
/// </summary>
public bool IsCancelled { get; private set; }
/// <summary>
/// Gets or sets value of IsDirty property.
/// </summary>
public bool IsDirty { get; set; }
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've been working as a software developer since 2000 and hold a Bachelor of Business degree from The Open Polytechnic of New Zealand. Computers are for people and I aim to build applications for people that they would want to use.