private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { PixelRectangle.SetValue(Canvas.LeftProperty, 0d); PixelRectangle.SetValue(Canvas.TopProperty, 0d); PixelRectangle.Width = ImagePixelWidth; PixelRectangle.Height = ImagePixelHeight; DrawRectFromPixelRect(); }
private void UpdatePixelRect() { Point imageStartPoint = Grid.TranslatePoint(new Point(StartX, StartY), Image); double pixelStartX = (imageStartPoint.X / Image.ActualWidth) * ImagePixelWidth; double pixelStartY = (imageStartPoint.Y / Image.ActualHeight) * ImagePixelHeight; double pixelWidth = (Rectangle.Width / Image.ActualWidth) * ImagePixelWidth; double pixelHeight = (Rectangle.Height / Image.ActualHeight) * ImagePixelHeight; PixelRectangle.SetValue(Canvas.LeftProperty, pixelStartX); PixelRectangle.SetValue(Canvas.TopProperty, pixelStartY); PixelRectangle.Width = pixelWidth; PixelRectangle.Height = pixelHeight; }