How to override MeasureOverride to find the size of ItemsControl

前端 未结 2 1334
耶瑟儿~
耶瑟儿~ 2020-12-20 21:42

I am developing a UserControl that consists of a block with a heading and a list of items (as ItemsControl). The usercontrol is added dynamically to a canvas. I

2条回答
  •  醉酒成梦
    2020-12-20 22:23

    Try using ActualWidth and ActualHeight properties.

    protected override Size MeasureOverride(Size availableSize)
    {
       var desiredSize = new Size();
       var sideLength = Math.Min(ActualWidth, ActualHeight);
    
       desiredSize.Width = sideLength;
       desiredSize.Height = sideLength;
    
       return desiredSize;
    }
    

提交回复
热议问题