Hi,
i am not having any such code but i can try by Pasting some Sample Hardcoded kind of stuff.
Hopefully you can create a logic from that.
Point newPoint=//Call RepositionImage method by passing appropriate values
YourObject.SetValue(Canvas.LeftProperty, newPoint.X);
YourObject.SetValue(Canvas.TopProperty, newPoint.Y);
private Point RepositionImage(Point currentPoint, int imageWidth, int imageHeight )
{
Point updatedPoint = new Point();
if (0 <= currentPoint.X && currentPoint.X <= 60)
{
updatedPoint.X = (60 - imageWidth) / 2;
}
else if (61 <= currentPoint.X && currentPoint.X <= 120)
{
updatedPoint.X = 60 + (60 - imageWidth) / 2;
}
else if (121 <= currentPoint.X && currentPoint.X <= 180)
{
updatedPoint.X = 120 + (60 - imageWidth) / 2;
}
//y
if (0 <= currentPoint.Y && currentPoint.Y <= 60)
{
updatedPoint.Y = (60 - imageWidth) / 2;
}
else if (61 <= currentPoint.Y && currentPoint.Y <= 120)
{
updatedPoint.Y = 60 + (60 - imageWidth) / 2;
}
else if (121 <= currentPoint.Y && currentPoint.Y <= 180)
{
updatedPoint.Y = 120 + (60 - imageWidth) / 2;
}
return updatedPoint;
}
Mark as answer if this post answered your question.
Harsh Bardhan