Question

I have made a control (looks like a grid) that can contain multiple children (UIElements). I measure and arrange the whole layout in code. Now some of these elements have defined a width in xaml and some doesn't have that.

How do I know in the measureOverride/arrangeoverride if a element has an fixed width or should use the whole available width?

Example XAML:

<MyControl>
   <TextBox x:Name="TextA" Text="TextFixed" Width="10"/>
   <TextBox x:Name="TextB" Text="TextStretch"/>
</MyControl>

Inside the MeasureOverride method after the uielement.Measure() the size is the minimal needed size for that element. I don't know how to see when I should calculate the available width for "TextB"...

Update:

In the MeasureOverride() both the elements have HorizontalAlignment 'Stretch' and after uiElement.Measure(availableSize) both have a DesiredSize.Width. That width is the minimal width it needs. With this information I am not able to know which of the two elements should be stretched or not.

Was it helpful?

Solution 2

The solution for my problem was to do a check in the ArrangeOverride() on the width when an element is supposed to stretch the width is double.NaN

OTHER TIPS

Look at Horizontal and VerticalAlignment property of the control.

If it is not Stretch the control should only take the fixed size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top