private void ResizableRect_SizeChanged(object sender, SizeChangedEventArgs e) { Point p = ResizableRect.TranslatePoint(o, DrawLineAndPoint); double w = ResizableRect.Width; if (p.X < 0) { //this.SetValue(ResizableRect, Canvas.SetLeft(ResizableRect, 0); ResizableRect.Width += p.X; return; } else if (p.X + ResizableRect.Width > this.DrawLineAndPoint.Width) { Canvas.SetRight(ResizableRect, this.DrawLineAndPoint.Width); ResizableRect.Width -= ResizableRect.Width - this.DrawLineAndPoint.Width + p.X; return; } Size newsize = e.NewSize; SelectedData.Vect1 = p.X * this.everyDisForPiexl.Vect1; SelectedData.Vect2 = (p.X + newsize.Width) * this.everyDisForPiexl.Vect1; //NOTICE: invoke event here! PassValuesEventArgs args = new PassValuesEventArgs(SelectedData); this.PassValuesEvent(this, args); }
///// <summary> ///// 渲染事件 ///// </summary> ///// <param name="drawingContext"></param> //protected override void OnRender(DrawingContext drawingContext) //{ // base.OnRender(drawingContext); //} /// <summary> /// 加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MyChart_Loaded(object sender, RoutedEventArgs e) { var layer = AdornerLayer.GetAdornerLayer(DrawLineAndPoint); //foreach (UIElement ui in DrawLineAndPoint.Children) layer.Add(new ResizeAdorner(ResizableRect)); this.xExtremeValue.Vect1 = 0; this.xExtremeValue.Vect2 = SourceData.Count; this.yExtremeValue.Vect1 = SourceData.Min(); this.yExtremeValue.Vect2 = SourceData.Max(); double xx = this.xExtremeValue.Vect2 - this.xExtremeValue.Vect1; double yy = this.yExtremeValue.Vect2 - this.yExtremeValue.Vect1 + 50000; this.everyDisForPiexl = new VectorChart2(xx / DrawLineAndPoint.Width, yy / DrawLineAndPoint.Height); Point p = ResizableRect.TranslatePoint(o, DrawLineAndPoint); SelectedData.Vect1 = p.X * this.everyDisForPiexl.Vect1; SelectedData.Vect2 = (p.X + this.ResizableRect.Width) * this.everyDisForPiexl.Vect1; this.AppendData(SourceData); }