I have a UserControl that looks like this:
<UserControl MaxHeight="32" MaxWidth="32" MinHeight="25" MinWidth="25"> <DockPanel> </DockPanel> </UserControl>
In addition to the min / max size limit, I want the control to always be drawn using Width = Height . Therefore, I override MeasureOverride and ArrangeOverride :
protected override Size MeasureOverride(Size availableSize) { var resultSize = new Size(0, 0); ((UIElement)Content).Measure(availableSize); var sideLength = Math.Min(((UIElement)Content).DesiredSize.Width, ((UIElement)Content).DesiredSize.Height); resultSize.Width = sideLength; resultSize.Height = sideLength; return resultSize; } protected override Size ArrangeOverride(Size finalSize) { ((UIElement)Content).Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)); return finalSize; }
I understand that I have to call Measure and Arrange for each child of a UserControl. Since the DocPanel is the only child of my UserControl and (in my opinion) is stored in the Content UserControl property, I just call Measure and Arrange on this Content property. However, UserControl is not displayed. What am I doing wrong?
wpf user-controls
skylap
source share