The size of the drawing (Rectangle) done by the DrawingContext is not the same thing as the size of the UIElement. There are no properties of the Image class nor the UIElement class that gets you the size of the drawing. You could define your own custom properties to be able to get the Height and Width of the drawn Rectangle:
public class MyImage : Image
{
protected override void OnRender(DrawingContext dc)
{
dc.DrawRectangle(Brushes.Red, null, new Rect(0, 0, 100, 100));
this.RectHeight = 100;
this.RectWidth = 100;
}
public double RectHeight { get; private set; }
public double RectWidth { get; private set; }
}
Source:
https://social.msdn.microsoft.com/Forums/en-US/2f512dd6-cf81-46a6-ab38-e9f7cc483030/wpf-how-to-get-a-custom-image-actualwidth-value[
^]