PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/ViewportUIContainer.cs

#
C# | 101 lines | 79 code | 16 blank | 6 comment | 12 complexity | c568951710ebb95ed07fb5c2fba58eed MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Markup;
  7. using Microsoft.Research.DynamicDataDisplay.Common;
  8. using System.Windows.Controls;
  9. namespace Microsoft.Research.DynamicDataDisplay.Charts
  10. {
  11. [ContentProperty("Content")]
  12. public class ViewportUIContainer : DependencyObject, IPlotterElement
  13. {
  14. public ViewportUIContainer() { }
  15. public ViewportUIContainer(FrameworkElement content)
  16. {
  17. this.Content = content;
  18. }
  19. private FrameworkElement content;
  20. [NotNull]
  21. public FrameworkElement Content
  22. {
  23. get { return content; }
  24. set { content = value; }
  25. }
  26. #region IPlotterElement Members
  27. void IPlotterElement.OnPlotterAttached(Plotter plotter)
  28. {
  29. this.plotter = plotter;
  30. if (Content == null) return;
  31. var plotterPanel = GetPlotterPanel(Content);
  32. //Plotter.SetPlotter(Content, plotter);
  33. if (plotterPanel == PlotterPanel.MainCanvas)
  34. {
  35. // if all four Canvas.{Left|Right|Top|Bottom} properties are not set,
  36. // and as we are adding by default content to MainCanvas,
  37. // and since I like more when buttons are by default in right down corner -
  38. // set bottom and right to 10.
  39. var left = Canvas.GetLeft(content);
  40. var top = Canvas.GetTop(content);
  41. var bottom = Canvas.GetBottom(content);
  42. var right = Canvas.GetRight(content);
  43. if (left.IsNaN() && right.IsNaN() && bottom.IsNaN() && top.IsNaN())
  44. {
  45. Canvas.SetBottom(content, 10.0);
  46. Canvas.SetRight(content, 10.0);
  47. }
  48. plotter.MainCanvas.Children.Add(Content);
  49. }
  50. }
  51. void IPlotterElement.OnPlotterDetaching(Plotter plotter)
  52. {
  53. if (Content != null)
  54. {
  55. var plotterPanel = GetPlotterPanel(Content);
  56. //Plotter.SetPlotter(Content, null);
  57. if (plotterPanel == PlotterPanel.MainCanvas)
  58. {
  59. plotter.MainCanvas.Children.Remove(Content);
  60. }
  61. }
  62. this.plotter = null;
  63. }
  64. private Plotter plotter;
  65. Plotter IPlotterElement.Plotter
  66. {
  67. get { return plotter; }
  68. }
  69. #endregion
  70. [AttachedPropertyBrowsableForChildren]
  71. public static PlotterPanel GetPlotterPanel(DependencyObject obj)
  72. {
  73. return (PlotterPanel)obj.GetValue(PlotterPanelProperty);
  74. }
  75. public static void SetPlotterPanel(DependencyObject obj, PlotterPanel value)
  76. {
  77. obj.SetValue(PlotterPanelProperty, value);
  78. }
  79. public static readonly DependencyProperty PlotterPanelProperty = DependencyProperty.RegisterAttached(
  80. "PlotterPanel",
  81. typeof(PlotterPanel),
  82. typeof(ViewportUIContainer),
  83. new FrameworkPropertyMetadata(PlotterPanel.MainCanvas));
  84. }
  85. }