private void OnPositionChanged(DependencyPropertyChangedEventArgs e) { PositionChanged.Raise(this, new PositionChangedEventArgs { Position = (Point)e.NewValue, PreviousPosition = (Point)e.OldValue }); ViewportPanel.SetX(this, Position.X); ViewportPanel.SetY(this, Position.Y); }
private void UpdateUI() { panel.Children.Clear(); if (plotter == null) { return; } var grid = Grid; if (grid == null) { return; } var bounds = grid.Grid.GetGridBounds(); Viewport2D.SetContentBounds(this, bounds); int width = grid.Width; int height = grid.Height; // todo not the best way to determine size of markers in case of warped grids. double deltaX = (grid.Grid[width - 1, 0].X - grid.Grid[0, 0].X) / width; double deltaY = (grid.Grid[0, height - 1].Y - grid.Grid[0, 0].Y) / height; for (int ix = 0; ix < width; ix++) { int localX = ix; Dispatcher.BeginInvoke(() => { for (int iy = 0; iy < height; iy++) { Ellipse ellipse = new Ellipse { MaxWidth = 10, MaxHeight = 10 }; var position = grid.Grid[localX, iy]; ViewportPanel.SetX(ellipse, position.X); ViewportPanel.SetY(ellipse, position.Y); ViewportPanel.SetViewportWidth(ellipse, deltaX / 2); ViewportPanel.SetViewportHeight(ellipse, deltaY / 2); if (localX % 10 == 0 && iy % 10 == 0) { ellipse.Fill = Brushes.Black; } else { ellipse.Fill = Brushes.Gray.MakeTransparent(0.7); } panel.Children.Add(ellipse); } }, DispatcherPriority.Background); } }