I have noticed that the “OnRender” overrides for some UI controls use the value of the element’s Width and Height properties in their calculations. If I haven’t explicitly set a manual width or height, but rather want it to fit to its contents, this usage in “OnRender” throws exceptions in the get accessor of those properties and prevents the UI from rendering.
For example, the OnRender method for Button is:
public override void OnRender(DrawingContext dc) {
var alpha = (this.IsEnabled) ? this.Alpha : (ushort)(this.Alpha / 2);
if (this.isPressed && this.IsEnabled)
dc.Scale9Image(0, 0, this.Width, this.Height, this.bitmapImageButtonDown, this.RadiusBorder, this.RadiusBorder, this.RadiusBorder, this.RadiusBorder, alpha);
else
dc.Scale9Image(0, 0, this.Width, this.Height, this.bitmapImageButtonUp, this.RadiusBorder, this.RadiusBorder, this.RadiusBorder, this.RadiusBorder, alpha);
}
Shouldn’t the “this.Width” and “this.Height” be replaced by something that is measured during the measure and arrange passes of the layout? I’m just guessing, but maybe “_renderWidth” and “_renderHeight” (equivalent to “ActualWidth” and “ActualHeight”)?