Keep lines, ellipses and polylines at the same position within an image during resizing (WinUI3)

youki 1,016 Reputation points
2024-04-18T22:09:16.7866667+00:00

Hello,

Is there an easy way to achieve it in WinUI3?

I have an image within a grid that is resizable manually and there are ellipses, lines and polylines which mark positions in the image.

<Grid>
    <Image Source="myPath\\myImage.png"></Image>
    <Polyline Stroke="#999999" Points="202,92 250,180 400,180"></Polyline>
    <Line Stroke="#999999" X1="0" Y1="235" X2="100" Y2="235" ></Line>
    <Ellipse Margin="70,150,0,0" Height="6" Width="6" StrokeThickness="1" Stroke="White"></Ellipse>
</Grid>

I have tried it with a relative panel but that doesn't seem to work.

Is it possible that this cannot be done without calculating the x and y coordinates/points using code in the SizeChanged event of the grid or image?

(I also tried the calculation but I'm not sure exactly how to do it (do I calculate the scaling or the percentages?!)

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
743 questions
{count} votes

1 answer

Sort by: Most helpful
  1. youki 1,016 Reputation points
    2024-04-20T22:50:02.2166667+00:00

    God, think I got it! (I mean it looks right.)

    // For images with same height & width.
    static double GetNewCoordinate(double newDimension, double initialDimension , double initialCoordinate)
    {	  	
    	return (newDimension / initialDimension) * initialCoordinate; 
    }
    

    Thank you!

    1 person found this answer helpful.
    0 comments No comments