1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows;
|
---|
6 | using System.Windows.Shapes;
|
---|
7 | using System.Windows.Media;
|
---|
8 |
|
---|
9 | namespace Microsoft.Research.DynamicDataDisplay.Charts
|
---|
10 | {
|
---|
11 | /// <summary>
|
---|
12 | /// Represents a base class for simple shapes with viewport-bound coordinates.
|
---|
13 | /// </summary>
|
---|
14 | public abstract class ViewportShape : Shape, IPlotterElement
|
---|
15 | {
|
---|
16 | static ViewportShape()
|
---|
17 | {
|
---|
18 | Type type = typeof(ViewportShape);
|
---|
19 | Shape.StrokeProperty.AddOwner(type, new FrameworkPropertyMetadata(Brushes.Blue));
|
---|
20 | Shape.StrokeThicknessProperty.AddOwner(type, new FrameworkPropertyMetadata(2.0));
|
---|
21 | }
|
---|
22 |
|
---|
23 | /// <summary>
|
---|
24 | /// Initializes a new instance of the <see cref="ViewportShape"/> class.
|
---|
25 | /// </summary>
|
---|
26 | protected ViewportShape() { }
|
---|
27 |
|
---|
28 | protected void UpdateUIRepresentation()
|
---|
29 | {
|
---|
30 | if (Plotter == null)
|
---|
31 | return;
|
---|
32 |
|
---|
33 | UpdateUIRepresentationCore();
|
---|
34 | }
|
---|
35 | protected virtual void UpdateUIRepresentationCore() { }
|
---|
36 |
|
---|
37 | #region IPlotterElement Members
|
---|
38 |
|
---|
39 | private Plotter2D plotter;
|
---|
40 | void IPlotterElement.OnPlotterAttached(Plotter plotter)
|
---|
41 | {
|
---|
42 | plotter.CentralGrid.Children.Add(this);
|
---|
43 |
|
---|
44 | Plotter2D plotter2d = (Plotter2D)plotter;
|
---|
45 | this.plotter = plotter2d;
|
---|
46 | plotter2d.Viewport.PropertyChanged += Viewport_PropertyChanged;
|
---|
47 |
|
---|
48 | UpdateUIRepresentation();
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
|
---|
52 | {
|
---|
53 | OnViewportPropertyChanged(e);
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected virtual void OnViewportPropertyChanged(ExtendedPropertyChangedEventArgs e)
|
---|
57 | {
|
---|
58 | UpdateUIRepresentation();
|
---|
59 | }
|
---|
60 |
|
---|
61 | void IPlotterElement.OnPlotterDetaching(Plotter plotter)
|
---|
62 | {
|
---|
63 | Plotter2D plotter2d = (Plotter2D)plotter;
|
---|
64 | plotter2d.Viewport.PropertyChanged -= Viewport_PropertyChanged;
|
---|
65 | plotter.CentralGrid.Children.Remove(this);
|
---|
66 |
|
---|
67 | this.plotter = null;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public Plotter2D Plotter
|
---|
71 | {
|
---|
72 | get { return plotter; }
|
---|
73 | }
|
---|
74 |
|
---|
75 | Plotter IPlotterElement.Plotter
|
---|
76 | {
|
---|
77 | get { return plotter; }
|
---|
78 | }
|
---|
79 |
|
---|
80 | #endregion
|
---|
81 | }
|
---|
82 | }
|
---|