First, thank you for your time.
I have created a wpf desktop applciation. On the view there is an InkCanvas control. After a png file is loaded into the canvas the user has the ability to modify this image in numerous ways. After the user colors, resizes and moves the image around, the user then clicks the Save button. The save button should not save the entire contents of the canvas but just the modified image that was placed on the canvas. In order for the code to just save a small specific rectangle of the canvas, I need to know where the image is and its dimensions. I can successfully get the width and height of the image, but I can't seem to get the top and left coordinates of the image on the canvas.
Here is the Save method:
private void Save_Click(object sender, RoutedEventArgs e)
var filename = General.PromptForSaveFilename();
if (filename != null)
foreach (Image child in inkCanvas.Children)
if (child.Source != null && child.Source.ToString().Contains(".png"))
var element = (UIElement) child;
double top = 0.0D, right = 0.0D, bottom = 0.0D, left = 0.0D;
GetElementDimensions(element, out top, out left, out bottom, out right);
// The value for left and top are 0.0! This is the problem.
// Return the dimensions of this element. This routine is wrong! The top and left values are 0!?
private static void GetElementDimensions(UIElement element, out double top, out double left, out double bottom, out double right)
top = InkCanvas.GetTop(element);
left = InkCanvas.GetLeft(element);
bottom = InkCanvas.GetBottom(element);
right = InkCanvas.GetRight(element);
// It's possible that some of the values are NaN or infinity. Reset those values to 0.
// If the incoming value is not reasonable, i.e. NaN or Infinity, then set it to 0.0; otherwise leave it alone.
private static void EnsureReasonableValue(ref double value)
value = 0.0D;
// Return true if the incoming value is reasonable (not infinity); otherwise return false.
public static bool IsFinite(double value)
return !double.IsNaN(value) && !double.IsInfinity(value);
Again, thank you for your time.