PageRenderTime 50ms CodeModel.GetById 47ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Navigation/Navigation/RectangleSelectionAdorner.cs

#
C# | 48 lines | 39 code | 7 blank | 2 comment | 1 complexity | fffa00e57e23884679f381c3a2e5b132 MD5 | raw file
 1using System.Windows;
 2using System.Windows.Documents;
 3using System.Windows.Media;
 4
 5namespace Microsoft.Research.DynamicDataDisplay.Navigation
 6{
 7    /// <summary>Helper class to draw semitransparent rectangle over the
 8    /// selection area</summary>
 9	public sealed class RectangleSelectionAdorner : Adorner {
10
11		private Rect? border = null;
12		public Rect? Border {
13			get { return border; }
14			set { border = value; }
15		}
16
17		public Brush Fill {
18			get { return (Brush)GetValue(FillProperty); }
19			set { SetValue(FillProperty, value); }
20		}
21
22		public static readonly DependencyProperty FillProperty =
23			DependencyProperty.Register(
24			  "Fill",
25			  typeof(Brush),
26			  typeof(RectangleSelectionAdorner),
27			  new FrameworkPropertyMetadata(
28				  new SolidColorBrush(Color.FromArgb(60, 100, 100, 100)),
29				  FrameworkPropertyMetadataOptions.AffectsRender));
30
31		private Pen pen;
32		public Pen Pen {
33			get { return pen; }
34			set { pen = value; }
35		}
36
37		public RectangleSelectionAdorner(UIElement element)
38			: base(element) {
39			pen = new Pen(Brushes.Black, 1.0);
40		}
41
42		protected override void OnRender(DrawingContext dc) {
43			if (border.HasValue) {
44				dc.DrawRectangle(Fill, pen, border.Value);
45			}
46		}
47	}
48}