PageRenderTime 35ms CodeModel.GetById 19ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/ILSpy/Controls/DockedPane.cs

http://github.com/icsharpcode/ILSpy
C# | 76 lines | 49 code | 10 blank | 17 comment | 12 complexity | 0eec4653ac488dae6e812f395f18e4de MD5 | raw file
 1// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Windows;
21using System.Windows.Controls;
22using System.Windows.Input;
23
24namespace ICSharpCode.ILSpy.Controls
25{
26	class DockedPane : Control
27	{
28		static DockedPane()
29		{
30			DefaultStyleKeyProperty.OverrideMetadata(typeof(DockedPane), new FrameworkPropertyMetadata(typeof(DockedPane)));
31		}
32		
33		public static readonly DependencyProperty TitleProperty =
34			DependencyProperty.Register("Title", typeof(string), typeof(DockedPane));
35		
36		public string Title {
37			get { return (string)GetValue(TitleProperty); }
38			set { SetValue(TitleProperty, value); }
39		}
40		
41		public static readonly DependencyProperty ContentProperty =
42			DependencyProperty.Register("Content", typeof(object), typeof(DockedPane));
43		
44		public object Content {
45			get { return GetValue(ContentProperty); }
46			set { SetValue(ContentProperty, value); }
47		}
48		
49		public override void OnApplyTemplate()
50		{
51			base.OnApplyTemplate();
52			Button closeButton = (Button)this.Template.FindName("PART_Close", this);
53			if (closeButton != null) {
54				closeButton.Click += closeButton_Click;
55			}
56		}
57		
58		void closeButton_Click(object sender, RoutedEventArgs e)
59		{
60			if (CloseButtonClicked != null)
61				CloseButtonClicked(this, e);
62		}
63		
64		public event EventHandler CloseButtonClicked;
65		
66		protected override void OnKeyDown(KeyEventArgs e)
67		{
68			base.OnKeyDown(e);
69			if (e.Key == Key.F4 && e.KeyboardDevice.Modifiers == ModifierKeys.Control || e.Key == Key.Escape) {
70				if (CloseButtonClicked != null)
71					CloseButtonClicked(this, e);
72				e.Handled = true;
73			}
74		}
75	}
76}