문제

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.

도움이 되었습니까?

해결책 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

다른 팁

Look at Horizontal and VerticalAlignment property of the control.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top