Reputation: 113
I have an app in C# WF, where user move and zoom image. I want to draw ellipse on Image control because ellipse remains in place, and don't moves when I modify the image.
View:
<Grid>
<Canvas Name="cavRoot" Opacity="1">
<Image Name="highresmap4" Source="highresmap4.png" Canvas.Left="0" Canvas.Top="0" Width="1473" Height="770">
</Image>
</Canvas>
</Grid>
Model:
class draw
{
public static void circle(double x, double y, int width, int height, Canvas cv)
{
Ellipse circle = new Ellipse()
{
Width = width,
Height = height,
Stroke = Brushes.Red,
StrokeThickness = 6
};
cv.Children.Add(circle);
circle.SetValue(Canvas.LeftProperty, (double)x);
circle.SetValue(Canvas.TopProperty, (double)y);
}
}
ViewModel:
draw.circle(x, y, 10, 10, cavRoot);
Upvotes: 1
Views: 623
Reputation: 169170
You could put the Image
in a Grid
and use the Margin
property of the Ellipse
to specify its position within the Image
:
public static void circle(double x, double y, int width, int height, Panel cv)
{
Ellipse circle = new Ellipse()
{
Width = width,
Height = height,
Stroke = Brushes.Red,
StrokeThickness = 6,
Margin = new Thickness(x, y, 0, 0)
};
cv.Children.Add(circle);
}
XAML:
<Grid x:Name="theGrid">
<Image Name="highresmap4" Source="highresmap4.png" Width="1473" Height="770" />
</Grid>
Upvotes: 1