PageRenderTime 31ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/BookReader/BookReader/Dialogs/DialogWindow.cs

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