WrapPanel: Trying to make the ItemWidth equal to the max width of any one element

后端 未结 3 558
情话喂你
情话喂你 2021-01-12 07:01

Hopefully no one else has already asked this question, but I have searched and cannot find any mention. Feel free to point me in the right direction if I missed another que

3条回答
  •  感情败类
    2021-01-12 07:45

    try setting the itemwidth property to Auto... see here:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.wrappanel.itemwidth(v=vs.110).aspx

    to perform this "width set" programmatically, you could do the following, once the control has been rendered.

    protected override void OnRender(DrawingContext dc)
    {
    
    int largest = 0;
    foreach(UIElement child in this.myWrapPanel.Children)
    {
        if(child.Width>largest)
            largest = child.Width;
    }
    
    this.myWrapPanel.ItemWidth = largest;
    
    
    }
    

提交回复
热议问题