PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

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