title: Dynamically setting background colour of a Silverlight control (Listbox)
body: <p>How do I set the background colour of items in a list box dynamically? i.e. there is some property on my business object that I'm binding too, so based on some business rules I want the background colour to be different?</p>
  
  <pre><code>        &lt;ListBox Background="Red"&gt;
        &lt;ListBox.ItemContainerStyle&gt;
            &lt;Style TargetType="ListBoxItem"&gt;
                &lt;Setter Property="Background" Value="Red"/&gt;
            &lt;/Style&gt;
        &lt;/ListBox.ItemContainerStyle&gt;
   &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal"
                                  Margin="5"&gt;
                          &lt;TextBlock VerticalAlignment="Bottom"
                                     FontFamily="Comic Sans MS"
                                     FontSize="12"
                                     Width="70"
                                     Text="{Binding Name}" /&gt;
                          &lt;TextBlock VerticalAlignment="Bottom"
                                     FontFamily="Comic Sans MS"
                                     FontSize="12"
                                     Width="70"
                                     Text="{Binding Age}" /&gt;
                       &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
          &lt;/ListBox.ItemTemplate&gt;
        &lt;/ListBox&gt;
  </code></pre>
  
  <p>EDIT: It says <a href="http://msdn.microsoft.com/en-us/library/cc189093(VS.95).aspx" rel="nofollow noreferrer">here</a></p>
  
  <blockquote>
    <p>In Silverlight, you must add x:Key
    attributes to your custom styles and
    reference them as static resources.
    Silverlight does not support implicit
    styles applied using the TargetType
    attribute value.</p>
  </blockquote>
  
  <p>Does this impact my approach?</p>