WPF: Grid with column/row margin/padding?

前端 未结 15 1105
梦毁少年i
梦毁少年i 2020-12-07 23:57

Is it easily possible to specify a margin and/or padding for rows or columns in a WPF Grid?

I could of course add extra columns to space things out,

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 00:09

    Thought I'd add my own solution because nobody yet mentioned this. Instead of designing a UserControl based on Grid, you can target controls contained in grid with a style declaration. Takes care of adding padding/margin to all elements without having to define for each, which is cumbersome and labor-intensive.For instance, if your Grid contains nothing but TextBlocks, you can do this:

    
    

    Which is like the equivalent of "cell padding".

提交回复
热议问题