WPF FlowDocument Table - AutoFit option?

前端 未结 4 1779
臣服心动
臣服心动 2021-01-13 11:23

I want a table to logically size the columns according to the contents. Is this possible in WPF?

alt text http://img43.imageshack.us/img43/2640/flowdocument.jpg

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 12:02

    Actually, Microsoft recommends to use a Grid instead of table for this purpose: docs.microsoft.com: Table vs Grid

    Alas, Grid does not support simple grid lines out of the box. Microsoft says the Grid.ShowGridLines is only for design purposes and draws rather ugly dashed lines. Micrsoft wants you to draw Gridlines yourself. How lazy is that from Microsoft ?

    Here is some sample code how this can be done:

    
      
        
          
            
              
              
            
            
              
              
            
            
              
    
            
            
              
            
            
              
            
            
              
            
            
              
            
          
        
      
    
    

    The main idea is to set each TextBox inside a Border and to decide for each Border which side needs a borderline.

    To get precise 1 pixel line, one must set Grid.RenderOptions.EdgeMode="Aliased" and Grid.UseLayoutRounding="True".

提交回复
热议问题