How do I space out the child elements of a StackPanel?

前端 未结 11 2125
长情又很酷
长情又很酷 2020-12-04 06:11

Given a StackPanel:


  Apple
  Banana
  

        
11条回答
  •  鱼传尺愫
    2020-12-04 07:00

    Another nice approach can be seen here: http://blogs.microsoft.co.il/blogs/eladkatz/archive/2011/05/29/what-is-the-easiest-way-to-set-spacing-between-items-in-stackpanel.aspx Link is broken -> this is webarchive of this link.

    It shows how to create an attached behavior, so that syntax like this would work:

    
       
       

    This is the easiest & fastest way to set Margin to several children of a panel, even if they are not of the same type. (I.e. Buttons, TextBoxes, ComboBoxes, etc.)

提交回复
热议问题