title: How do I add or access variables inside an XAML file, in a WPF application?
body: <p>I want to stick to the DRY principle, so I have about 20 buttons in a grid, and they all have the same margin, they look like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Button Grid.Column="0" Grid.Row="0" Margin="3"/&gt;
  &lt;Button Grid.Column="0" Grid.Row="1" Margin="3"/&gt;
  &lt;Button Grid.Column="0" Grid.Row="2" Margin="3"/&gt;
  &lt;Button Grid.Column="0" Grid.Row="3" Margin="3"/&gt;
  &lt;Button Grid.Column="0" Grid.Row="4" Margin="3"/&gt;
  &lt;Button Grid.Column="1" Grid.Row="0" Margin="3"/&gt;
  &lt;Button Grid.Column="1" Grid.Row="1" Margin="3"/&gt;
  &lt;Button Grid.Column="1" Grid.Row="2" Margin="3"/&gt;
  &lt;Button Grid.Column="1" Grid.Row="3" Margin="3"/&gt;
  &lt;Button Grid.Column="1" Grid.Row="4" Margin="3"/&gt;
  &lt;Button Grid.Column="2" Grid.Row="0" Margin="3"/&gt;
  &lt;Button Grid.Column="2" Grid.Row="1" Margin="3"/&gt;
  &lt;Button Grid.Column="2" Grid.Row="2" Margin="3"/&gt;
  &lt;Button Grid.Column="2" Grid.Row="3" Margin="3"/&gt;
  &lt;Button Grid.Column="2" Grid.Row="4" Margin="3"/&gt;
  &lt;Button Grid.Column="3" Grid.Row="0" Margin="3"/&gt;
  &lt;Button Grid.Column="3" Grid.Row="1" Margin="3"/&gt;
  &lt;Button Grid.Column="3" Grid.Row="2" Margin="3"/&gt;
  &lt;Button Grid.Column="3" Grid.Row="3" Margin="3"/&gt;
  &lt;Button Grid.Column="3" Grid.Row="4" Margin="3"/&gt;
  </code></pre>
  
  <p>I want to add a variable called something like "ButtonMargin", set it to 3, and then set the margin of each of these buttons to ButtonMargin because in case I want to change it in the future this way I'll only change one variable instead of 20.</p>
  
  <p>I tried having an actual variable inside the .cs file <code>string ButtonMargin;</code> and set it to <code>"3"</code> inside the constructor, but I get an invalid markup error when writing <code>Margin = ButtonMargin</code> or <code>Margin = this.ButtonMargin</code> inside the XAML file.</p>
  
  <p>How do I do it properly?</p>