About WPF Layout

Best Practices

  • Avoid fixed positions - use the Alignment properties in combination with Margin to position elements in a panel
  • Avoid fixed sizes - set the Width and Height of elements to Auto whenever possible.
  • Don't abuse the canvas panel to layout elements. Use it only for vector graphics.
  • Use a StackPanel to layout buttons of a dialog
  • Use a GridPanel to layout a static data entry form. Create a Auto sized column for the labels and a Star sized column for the TextBoxes.
  • Use an ItemControl with a grid panel in a DataTemplate to layout dynamic key value lists. Use the SharedSize feature to synchronize the label widths.

Clipping

Layout panels typically clip those parts of child elements that overlap the border of the panel. This behavior can be controlled by setting the ClipToBounds property to true or false.

 

posted @ 2010-05-21 07:18  i'm zjz  阅读(243)  评论(0编辑  收藏  举报