Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your XAML, set your background to black. Then in your user control, use the DesignerProperties to set the background at runtime:</p> <p><strong>XAML</strong></p> <pre><code>&lt;UserControl .... Background="Black" .... &gt; </code></pre> <p><strong>Code Behind</strong></p> <pre><code>public YourUserControl() { InitializeComponent(); if( !System.ComponentModel.DesignerProperties.GetIsInDesignMode( this ) ) { this.Background = Brushes.Transparent; } } </code></pre> <p><br /></p> <hr> <h2><strong>Alternate Method</strong></h2> <p><strong>UserControl:</strong></p> <p>In your user control, do not declare a background color:</p> <pre><code>&lt;UserControl ... namespaces ...&gt; </code></pre> <p><strong>UserControl Code Behind:</strong></p> <p>In your user control's constructor, use the DesignTime method as above, but check to see if it is Design Mode (opposite check from other method):</p> <pre><code>public YourUserControl() { InitializeComponent(); if( System.ComponentModel.DesignerProperties.GetIsInDesignMode( this ) ) { this.Background = Brushes.Black; } } </code></pre> <p><strong>App.xaml:</strong></p> <p>Finally, in your App.xaml, add a style to set a background color for UserControls:</p> <pre><code>&lt;Application.Resources&gt; &lt;Style TargetType="{x:Type UserControl}"&gt; &lt;Setter Property="Background" Value="Black" /&gt; &lt;/Style&gt; &lt;/Application.Resources&gt; </code></pre> <p>Here's what's happening: </p> <ol> <li>The App.xaml will effect the UserControl at design time because a typed style is applied on an object automatically, but it is <strong>not</strong> applied to a derived object (UserControl in this case). So, at design time, VS thinks it should apply the style, but at runtime, it will be ignored.</li> <li>The <code>GetIsInDesignMode</code> check will effect the UserControl when viewing the control in a Window that is using the UserControl because VS is compiling the UserControl at design time in order to render it in the Visual Designer.</li> </ol> <p>HTH's</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload