title: Dock and Anchor in WPF
body: <p>I am coming from a WinForms background and am starting to learn WPF.  I've gone through a set of tutorials at Pluralsight, but am having a little difficulty with handling resizing.  </p>
  
  <p>When resizing, my textboxes don't seem to be "anchoring" in the way I would want.  I'm including the xaml below with notes in it as to the behavior I am looking for.  Any feedback regarding best practices would be very much appreciated.  The code just "feels" a little awkward to me, but I'm not sure if that is because it's just new to me, or if there are easier/better ways of doing what I am attempting.  </p>
  
  <p>To get an idea of what things look like without needing to load the XAML below - here are before and after resizing the form screenshots.
  <a href="http://dboasis.com/screenshots/beforeresize.jpg" rel="nofollow noreferrer">Before Resize http://dboasis.com/screenshots/beforeresize.jpg</a>
  <a href="http://dboasis.com/screenshots/afterresize.jpg" rel="nofollow noreferrer">After Resize http://dboasis.com/screenshots/afterresize.jpg</a></p>
  
  <p>I'm hoping for suggestions both how to handle the resize issues, as well as best practices after seeing how I've attempted to do it in the XAML.</p>
  
  <p>Also - the xaml does implement DevExpress controls - if anyone wants me to redo the form and not use 3rd party controls so they more easily make suggestions, I am happy to do so.  </p>
  
  <pre><code>&lt;dx:DXWindow
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
      xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
      xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" x:Class="DXTemplateSandbox.MainWindow"
      Title="MainWindow" Height="437" Width="641"&gt;
  &lt;Grid&gt;
      &lt;dx:DXTabControl x:Name="tabcntMainTab"&gt;
          &lt;dx:DXTabItem x:Name="tabUserList" Header="User List"&gt;
              &lt;Grid Background="Transparent"&gt;
  
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition x:Name="SelectLabel" Height="30" /&gt;
                      &lt;RowDefinition x:Name="OpenDataFile" Height="34" /&gt;
                      &lt;RowDefinition x:Name="DataGridLayoutRow" Height="185*" /&gt;
                      &lt;RowDefinition x:Name="AppPrefsInfo" Height="110" /&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;StackPanel Grid.Row="1" Orientation="Horizontal" Margin="10,0"&gt;
                      &lt;!-- 
                      The DataFileLocation not resizing the width.  How do I instead lock the vertical size, but allow width to
                      resize with form?
                      --&gt;
                      &lt;TextBox Name="DataFileLocation" Width="419" Margin="0,5" HorizontalAlignment="Stretch" /&gt;
  
                      &lt;!--
                      How do I get the SelectData button stay immediately to the right of the DatFileLocation textbox when resizing?
                      --&gt;
                      &lt;Button Name="SelectData" Content="..." Width="40" Margin="5" Click="SelectData_Click"/&gt;
                      &lt;DockPanel&gt;
                          &lt;!-- I would like the "Go" button to stay anchored to the right when resizing. --&gt;
                          &lt;Button x:Name="GoButton" 
                                  Content="Go" 
                                  Width="66" 
                                  DockPanel.Dock="Right"
                                  HorizontalAlignment="Right"
                                  VerticalAlignment="Top"
                                  Margin="50,5,5,5" 
                                  Click="GoButton_Click" /&gt;
                      &lt;/DockPanel&gt;
  
                  &lt;/StackPanel&gt;
  
                  &lt;!--
                  --&gt;
                  &lt;dxg:GridControl Grid.Row="2" Margin="5" &gt;
                      &lt;dxg:GridControl.View&gt;
                          &lt;dxg:TableView ShowGroupPanel="False"/&gt;
                      &lt;/dxg:GridControl.View&gt;
                  &lt;/dxg:GridControl&gt;
  
                  &lt;Label Content="Select Data File" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" Height="26" Grid.RowSpan="2" Width="91"/&gt;
  
                  &lt;!-- 
                  Is using a grid inside a parent grid cell the best way of doing this?  I'm using stackpanels in each of the rows in the
                  child grid.  Is there a better way of doing this?  
                  --&gt;
                  &lt;Grid x:Name="AppPrefsGrid" Grid.Row="3" &gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition/&gt;
                          &lt;RowDefinition/&gt;
                          &lt;RowDefinition/&gt;
                      &lt;/Grid.RowDefinitions&gt;
                      &lt;!--
                      Ideally I would like the text boxes to grow and shrink at the same rate as form is resized, and leave the labels the same width.  I don't know
                      if this is practical however.
                      --&gt;
                      &lt;StackPanel Grid.Row="0" Orientation="Horizontal"&gt;
                          &lt;Label Content="Registration Name:" Width="112" Margin="5"/&gt;
                          &lt;TextBox Name="RegNameTextBox" Width="175" Margin="5" IsEnabled="False"/&gt;
                          &lt;Label Content="Install Date:" Width="84" Margin="10,5,5,5"/&gt;
                          &lt;TextBox Name="InstallDateTextBox" Width="175" Margin="5" IsEnabled="False"/&gt;
                      &lt;/StackPanel&gt;
                      &lt;StackPanel Grid.Row="1" Orientation="Horizontal"&gt;
                          &lt;Label Content="Registration Number:" Width="112" Margin="5"/&gt;
                          &lt;TextBox Name="RegNumberTextBox" Width="175" Margin="5" IsEnabled="False"/&gt;
                          &lt;Label Content="Data File Version:" Width="84" Margin="10,5,5,5"/&gt;
                          &lt;TextBox Name="DataVersionTextBox" Width="175" Margin="5" IsEnabled="False"/&gt;
                      &lt;/StackPanel&gt;
                      &lt;StackPanel Grid.Row="2" Orientation="Horizontal"&gt;
                          &lt;Label Content="Edition Code:" Width="112" Margin="5"/&gt;
                          &lt;TextBox Name="EditionCodeTextBox" Width="175" Margin="5" IsEnabled="False"/&gt;
                          &lt;Label Content="User Count:" Width="84" Margin="10,5,5,5"/&gt;
                          &lt;TextBox Name="UserCountTextBox" Width="175" Margin="5" IsEnabled="False"/&gt;
                      &lt;/StackPanel&gt;
  
  
                  &lt;/Grid&gt;
  
              &lt;/Grid&gt;
  
          &lt;/dx:DXTabItem&gt;
          &lt;dx:DXTabItem x:Name="tabKeyGen" Header="Key Generator"/&gt;
      &lt;/dx:DXTabControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>