title: Most optimal way to design a view with labels and inputs in XAML
body: <p>Every time someone asks me to provide an interface to input values, I find myself creating grids with a lot of rows and columns. Tried to look for an answer to this question but find it hard</p>
  
  <h2>Code</h2>
  
  <pre><code> &lt;Grid HorizontalAlignment="Left" VerticalAlignment="Top"&gt;
              &lt;Grid.Resources&gt;
                  &lt;Style TargetType="RowDefinition"&gt;
                      &lt;Setter Property="Height" Value="25"/&gt;
                  &lt;/Style&gt;
                  &lt;Style TargetType="TextBox"&gt;
                      &lt;Setter Property="Margin" Value="2"/&gt;
                  &lt;/Style&gt;
              &lt;/Grid.Resources&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="60"/&gt;
                  &lt;ColumnDefinition Width="150"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition/&gt;
                  &lt;RowDefinition/&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;TextBlock Grid.Row="0" Grid.Column="0"&gt;Input 1&lt;/TextBlock&gt;
              &lt;TextBox Grid.Row="0" Grid.Column="1"&gt;&lt;/TextBox&gt;
              &lt;TextBlock Grid.Row="1" Grid.Column="0"&gt;Input 2&lt;/TextBlock&gt;
              &lt;TextBox Grid.Row="1" Grid.Column="1"&gt;&lt;/TextBox&gt;
          &lt;/Grid&gt;
  </code></pre>
  
  <h2>Result</h2>
  
  <p><img src="https://i.stack.imgur.com/ubEgi.png" alt="Example"></p>
  
  <p>Questions that come to mind are if there are any performance considerations or if there is another method that removes the need of maintaining attributes with row and column numbers.</p>
  
  <p>The option of creating a custom control with label and input is discussed <a href="https://stackoverflow.com/questions/1015226/wpf-best-practice-for-the-run-of-the-mill-labelinput-control">here</a> however that would introduce more overhead.</p>
  
  <p>Creating the layout seems somewhat repetitive which makes me wonder if there is a tool for exactly this.</p>
  
  <h2>Question</h2>
  
  <p>Is this the most optimal way of doing it? If not, why and how should it be done?</p>