static void OnForegroundChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            GraphGrid grid = obj as GraphGrid;

            if (grid != null)
            {
                grid.CreatePen();
            }
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.graphGrid = this.Template.FindName("PART_GraphGrid", this) as GraphGrid;
            this.canvas    = this.Template.FindName("PART_Canvas", this) as Canvas;
            Debug.Assert(this.graphGrid != null && this.canvas != null, "Template for GraphDataBar does not have a GraphGrid (named PART_GraphGrid) and/or a Canvas (named PART_Canvas) in it!");
            if (this.graphGrid != null && this.canvas != null)
            {
                this.graphGrid.SideBar = this.SideBar;
                this.SideBar.SetBinding(HeightProperty, new Binding {
                    Source = this.graphGrid, Path = new PropertyPath(GraphGrid.ActualHeightProperty)
                });
                this.SideBar.SetBinding(GraphDataSideBar.ForegroundProperty, new Binding {
                    Source = this.graphGrid, Path = new PropertyPath(GraphGrid.ForegroundProperty)
                });
                this.SideBar.SetBinding(GraphDataSideBar.BackgroundProperty, new Binding {
                    Source = this.graphGrid, Path = new PropertyPath(GraphGrid.BackgroundProperty)
                });

                this.SideBar.SetRange(0, this.DefaultYRange);

                this.graphGrid.SetBinding(GraphGrid.HighlightRangeStartProperty, new Binding {
                    Source = this, Path = new PropertyPath(HighlightRangeStartProperty)
                });

                var multiBinding = new MultiBinding {
                    Converter = new HighlightStopConverter()
                };
                multiBinding.Bindings.Add(new Binding {
                    Source = this, Path = new PropertyPath(HighlightRangeStopProperty)
                });
                multiBinding.Bindings.Add(new Binding {
                    Source = this, Path = new PropertyPath(DataRangeStopProperty)
                });
                this.graphGrid.SetBinding(GraphGrid.HighlightRangeStopProperty, multiBinding);

                this.graphGrid.SizeChanged += OnYAxisChanged;

                UpdateRangeValues();

                foreach (var shape in this.shapeTable.Values)
                {
                    this.canvas.Children.Add(shape);
                }

                this.canvas.Children.Add(this.pausePointShape);
            }
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.graphGrid = this.Template.FindName("PART_GraphGrid", this) as GraphGrid;
            this.canvas = this.Template.FindName("PART_Canvas", this) as Canvas;
            Debug.Assert(this.graphGrid != null && this.canvas != null, "Template for GraphDataBar does not have a GraphGrid (named PART_GraphGrid) and/or a Canvas (named PART_Canvas) in it!");
            if (this.graphGrid != null && this.canvas != null)
            {
                this.graphGrid.SideBar = this.SideBar;
                this.SideBar.SetBinding(HeightProperty, new Binding { Source = this.graphGrid, Path = new PropertyPath(GraphGrid.ActualHeightProperty) });
                this.SideBar.SetBinding(GraphDataSideBar.ForegroundProperty, new Binding { Source = this.graphGrid, Path = new PropertyPath(GraphGrid.ForegroundProperty) });
                this.SideBar.SetBinding(GraphDataSideBar.BackgroundProperty, new Binding { Source = this.graphGrid, Path = new PropertyPath(GraphGrid.BackgroundProperty) });

                this.SideBar.SetRange(0, this.DefaultYRange);

                this.graphGrid.SetBinding(GraphGrid.HighlightRangeStartProperty, new Binding { Source = this, Path = new PropertyPath(HighlightRangeStartProperty) });

                var multiBinding = new MultiBinding { Converter = new HighlightStopConverter() };
                multiBinding.Bindings.Add(new Binding { Source = this, Path = new PropertyPath(HighlightRangeStopProperty) });
                multiBinding.Bindings.Add(new Binding { Source = this, Path = new PropertyPath(DataRangeStopProperty) });
                this.graphGrid.SetBinding(GraphGrid.HighlightRangeStopProperty, multiBinding);

                this.graphGrid.SizeChanged += OnYAxisChanged;

                UpdateRangeValues();

                foreach (var shape in this.shapeTable.Values)
                {
                    this.canvas.Children.Add(shape);
                }

                this.canvas.Children.Add(this.pausePointShape);
            }
        }