PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/BookReader/BookReader/Dialogs/DialogWindow.cs

#
C# | 54 lines | 45 code | 8 blank | 1 comment | 5 complexity | 125ab0945b98054c3106820dcd85065d MD5 | raw file
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using BookReader.Common;
  4. namespace BookReader.Dialogs
  5. {
  6. public class DialogWindow : Window
  7. {
  8. static DialogWindow()
  9. {
  10. // set the key to reference the style for this control
  11. FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
  12. typeof(DialogWindow), new FrameworkPropertyMetadata(typeof(DialogWindow)));
  13. }
  14. public bool CloseAble
  15. {
  16. get;
  17. set;
  18. }
  19. public DialogWindow()
  20. {
  21. if (!DesignHelper.IsInDesignMode())
  22. this.Owner = Application.Current.MainWindow;
  23. if (!DesignHelper.IsInDesignMode())
  24. this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  25. }
  26. public override void OnApplyTemplate()
  27. {
  28. base.OnApplyTemplate();
  29. Button close = this.Template.FindName("PART_Close", this) as Button;
  30. if (close != null)
  31. close.Click += new RoutedEventHandler(close_Click);
  32. }
  33. public void close_Click(object sender, RoutedEventArgs e)
  34. {
  35. if (CloseAble)
  36. this.Close();
  37. else
  38. this.Hide();
  39. }
  40. protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
  41. {
  42. base.OnMouseLeftButtonDown(e);
  43. this.DragMove();
  44. }
  45. }
  46. }