title: Setting WPF background Opacity programmatically
body: <p>I'm working on application which creates a new wpf border component for each row in a database. This means I've got to style the border component in C# rather than XAML (as far as I'm aware). The styling is all good so far apart from trying to set the background opacity.</p>
  
  <pre><code>motherboards.Add(new Border());
  Border moboBorder = motherboards[i];
  moboBorder.Width = 150;
  moboBorder.Height = 150;
  moboBorder.BorderBrush = Brushes.Black;
  moboBorder.Background = Brushes.White;
  moboBorder.CornerRadius = new CornerRadius(10);
  moboBorder.Margin = new Thickness(5);
  moboBorder.BorderThickness = new Thickness(1);
  </code></pre>
  
  <p>You can adjust the background opacity in XAML like so</p>
  
  <pre><code>&lt;Border BorderThickness="1" Height="100" Width="100"&gt;
      &lt;Border.BorderBrush&gt;
          &lt;SolidColorBrush Color="Black" Opacity="0.7"/&gt;
      &lt;/Border.BorderBrush&gt;
  &lt;/Border&gt;
  </code></pre>
  
  <p>But as I've said I'm creating the component in C# rather than XAML. I guess this is how you set the value in c#</p>
  
  <pre><code>moboBorder.Background.Opacity = //Value
  </code></pre>
  
  <p>However, I can't figure out what kind of value it takes, not just a straight up number, nothing from brushes than I can see and nothing like = new Opacity()</p>
  
  <p>I've tried googling around but everything is about setting the opacity for the whole element rather than just the background of it.</p>