Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Maintain canvas child position on resize

$
0
0

I have a mouse up event that draws an ellipse.  When the window is resized I want the balls to move and scale with the canvas - so if the ball is 10% from the top and 10% from the left, I want it to be in the same relative spot whether the canvas is 1000px wide or 50px wide.  Ideas?

            Ellipse ball = new Ellipse();
            ball.Width = 30;
            ball.Height = 30;
            ball.Fill = new SolidColorBrush(Colors.OrangeRed);

            Point p = Mouse.GetPosition(court);

            court.Children.Add(ball);
            Canvas.SetLeft(ball, p.X - (ball.Width/2.0));
            Canvas.SetTop(ball, p.Y - (ball.Height/2.0));



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>