/WPF Dialogs/Dialogs/DeleteDialog.xaml.cs
C# | 126 lines | 90 code | 10 blank | 26 comment | 3 complexity | ba6a30ae7bf6fdfa821669ef1a55e93f MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
-
- using WPF_Dialogs.Custom_Controls;
-
- namespace WPF_Dialogs.Dialogs
- {
- /// <summary>
- /// Interaction logic for Delete.xaml
- /// </summary>
- public partial class DeleteDialog : Window, IDialog
- {
- /// <summary>
- /// Gets or sets the dialog result value, which is the value that is returned from the <see cref="M:System.Windows.Window.ShowDialog"/> method.
- /// </summary>
- /// <value></value>
- /// <returns>A <see cref="T:System.Nullable`1"/> value of type <see cref="T:System.Boolean"/>. The default is false.</returns>
- /// <exception cref="T:System.InvalidOperationException">
- /// <see cref="P:System.Windows.Window.DialogResult"/> is set before a window is opened by calling <see cref="M:System.Windows.Window.ShowDialog"/>, or a window opened by calling <see cref="M:System.Windows.Window.Show"/>.</exception>
- public new EDialogResult DialogResult { set; get; }
- /// <summary>
- /// Gets or sets a value indicating whether the new object should be a folder or a file. DEFAULT: True
- /// </summary>
- /// <value><c>true</c> if the new object should be a folder; otherwise, <c>false</c>.</value>
- public bool IsFolder { get; set; }
- private string name;
-
- public DeleteDialog(string name)
- {
- InitializeComponent();
- this.buttonCancel.Focus();
- this.IsFolder = true;
- this.name = name;
- }
-
- #region public functions
- public EDialogResult showDialog()
- {
- this.ShowDialog();
- return this.DialogResult;
- }
- #endregion
-
- #region public Properties
- /// <summary>
- /// Sets the content of the label text.
- /// </summary>
- /// <value>The content of the label text.</value>
- public object LabelTextContent
- {
- set
- {
- this.labelText.Content = value;
- }
- }
-
- /// <summary>
- /// Sets the content of the button OK.
- /// </summary>
- /// <value>The content of the button OK.</value>
- public object ButtonOKContent
- {
- set
- {
- this.buttonOK.Content = value;
- }
- }
-
- /// <summary>
- /// Sets the content of the button cancel.
- /// </summary>
- /// <value>The content of the button cancel.</value>
- public object ButtonCancelContent
- {
- set
- {
- this.buttonCancel.Content = value;
- }
- }
- #endregion
-
- #region private functions
- private void DialogButton_clicked(object sender, RoutedEventArgs e)
- {
- DialogButton db = e.OriginalSource as DialogButton;
- this.DialogResult = db.DialogResult;
- if (this.DialogResult == EDialogResult.OK)
- delete();
- this.Close();
- }
-
- private new bool? ShowDialog()
- {
- return base.ShowDialog();
- }
-
- private void delete()
- {
- try
- {
- if (IsFolder)
- Directory.Delete(name);
- else
- {
- File.Delete(name);
- }
- }
- catch (IOException ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }