VIJI VIJI - 14 days ago 4
C# Question

MeasureOverride available size is infinity

I have implemented a simple custom control in

UWP
platform. My problem is when I placed this control inside the
Hub
I got this error.


System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has
been returned from a call to a COM component. at
Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)


Here
availableSize
width returns
infinity
, can anyone advise me how to resolve this problem?

<Hub>
<HubSection>
<DataTemplate>
<myControl:MySimpleControl />
</DataTemplate>
</HubSection>
</Hub>

Answer

When the custom control was added the children of StackPanel, throw the same exception. Because StackPanel width is infinity when Orientation is Horizontal. HubSection has also the same scenario like this.

So in this case have to allocated default(specific) Width for the control then call the InvalidateMeasure() to resolve this problem.