Alex Rivera | Logout

How to anchor controls in WPF?

Asked 2011-03-04T01:10:38.813
38

I have a a TreeView that fills the top part of the application, but since the number of items in the TreeView changes, my Apply button changes its position vertically. Is there a way to anchor it to the bottom part of the window, so it's always on the right bottom part of the window, i.e. 10x10 distance from the right bottom edge.

Edit
Report

1 Answer

41

To achieve anchoring, Set following properties:

  • Width="auto"
  • Height="auto"
  • VerticalAlignment="Stretch"
  • HorizontalAlignment="Stretch"
  • Set margins as needed.

Example:

    <TabControl

        Name="tabControl1"

        HorizontalAlignment="Stretch" 

        Margin="40,40,40,40"  

        Width="auto" 

        Height="auto" 

        VerticalAlignment="Stretch">
answered 2013-03-15T05:13:11.207

Your Answer