WPF: Grid with column/row margin/padding?

前端 未结 15 1106
梦毁少年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:23

    I ran into this problem while developing some software recently and it occured to me to ask WHY? Why have they done this...the answer was right there in front of me. A row of data is an object, so if we maintain object orientation, then the design for a particular row should be seperated (suppose you need to re-use the row display later on in the future). So I started using databound stack panels and custom controls for most data displays. Lists have made the occasional appearance but mostly the grid has been used only for primary page organization (Header, Menu Area, Content Area, Other Areas). Your custom objects can easily manage any spacing requirements for each row within the stack panel or grid (a single grid cell can contain the entire row object. This also has the added benefit of reacting properly to changes in orientation, expand/collapses, etc.

    
      
        
        
      
    
      
      
    
    

    or

    
      
      
    
    

    Your Custom controls will also inherit the DataContext if your using data binding...my personal favorite benefit of this approach.

提交回复
热议问题