title: Create a control in Resources and reuse it in XAML WPF
body: <p>I just try to create a simple Symbol/Geometry/Control and change and reuse it in several places in the same window.</p>
  
  <p>Example: a black square with a circle in the middle.</p>
  
  <p>The circle should then change between red and green (similar to a one-light stoplight). Doing it with images would work. I try to solve it as a Window resource, but I do not unterstand.</p>
  
  <p>The idea: I write it into a resource, here I try into a Canvas:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;Canvas x:Key="Ampel"&gt;
          &lt;Rectangle Fill="Black" HorizontalAlignment="Left" Height="52" Stroke="Black"       VerticalAlignment="Top" Width="50"/&gt;
          &lt;Ellipse x:Name="RedGreen" Fill="Red" HorizontalAlignment="Left" Height="27" Margin="11,12,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="0.214,0.256"/&gt;
      &lt;/Canvas&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>Then I would like to place it inside a Grid or a Panel, but how do I reference it?</p>
  
  <pre><code>&lt;Canvas x:Name="RedGreen1" Height="50" Width="50" DataContext="{DynamicResource Ampel}" /&gt; 
  </code></pre>
  
  <p>This does not return a compiler-error, but shows nothing in the window. It also doesn't work with WrapPanel or anything else.  </p>
  
  <p>And if it would work, how could I refer to it in code-behing for changing the color of the circle. Something like <code>RedGreen1.RedGreen.Fill=Brushes.Green</code>?</p>
  
  <p>I read the articles about stoplights. Is it really necessary to create an UserControl or is there a way to solve it with window.resources?</p>
  
  <p>General idea of the application is to have a list of parameters. Each one with a correct input is marked green and computation can only be started, if all parameters are marked green.</p>
  
  <p>And even if I get it running with red/green-images, I try to understand WPF/XAML better  and learn something.</p>
  
  <p>Thank you.</p>