title: How to use Canvas as the ItemsPanel for an ItemsControl in Silverlight 3
body: <p>I am trying to set the Canvas properties in an ItemsControl DataTemplate with Silverlight 3.  According to <a href="https://stackoverflow.com/questions/1265364/setting-canvas-properties-in-an-itemscontrol-datatemplate">this post</a>, the only way of doing that is to set it using the ItemsContainerStyle for the ContentPresenter type, since the Canvas properties only take effect on direct children of the Canvas.  This doesn't seem to work in SL3, since the ItemsControl doesn't have an ItemsContainerStyle property, so I tried a ListBox as advised by <a href="http://forums.silverlight.net/forums/p/11291/36677.aspx#36677" rel="nofollow noreferrer">this article</a>, but it still doesn't work.  From the XAML below, I would expect to see a green square, with the numbers 10, 30, 50, 70 cascading from "NW" to "SE" direction.  Can anyone tell me why they are all stacked on top of eachother in the NW corner?</p>
  
  <pre><code>&lt;UserControl x:Class="TestControl"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:System="clr-namespace:System;assembly=mscorlib" &gt;
      &lt;StackPanel&gt;
          &lt;ListBox&gt;
              &lt;ListBox.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;Canvas Background="Green" Width="100" Height="100" /&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ListBox.ItemsPanel&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;TextBox Text="{Binding}" /&gt;
                  &lt;/DataTemplate&gt;                
              &lt;/ListBox.ItemTemplate&gt;
              &lt;ListBox.ItemContainerStyle&gt;
                  &lt;Style TargetType="ContentPresenter"&gt;
                      &lt;Setter Property="Canvas.Left" Value="{Binding}" /&gt;
                      &lt;Setter Property="Canvas.Top" Value="{Binding}" /&gt;
                  &lt;/Style&gt;
              &lt;/ListBox.ItemContainerStyle&gt;
              &lt;ListBox.Items&gt;
                  &lt;System:Int32&gt;10&lt;/System:Int32&gt;
                  &lt;System:Int32&gt;30&lt;/System:Int32&gt;
                  &lt;System:Int32&gt;50&lt;/System:Int32&gt;
                  &lt;System:Int32&gt;70&lt;/System:Int32&gt;
              &lt;/ListBox.Items&gt;
          &lt;/ListBox&gt;
      &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>