title: Databind DockPanel
body: <p>I'm trying to databind a Dockpanel in wpf to a viewmodel collection. I'm using this in order to create a customizable form and so I will not know how many children should be in the dockpanel until runtime.</p>
  
  <p>The problem that I am having is that the attached property DockStyle.Dock doesn't seem to be getting applied when I set it from within a data template. The following xaml is a simplified version of what I am doing. I would expect the first button to fill up the top portion of the screen but what really happens is that they are stacked horizontally. Even hardcoding the DockPanel.Dock property has no effect on the layout of the buttons. When I look at the Visual Tree in XAMLPad I notice that there are ContentPresenters as children of the DockPanel instead of the buttons. Do ContentPresenters get layed out differently then other elements? Is there another technique to databinding to DockPanels?</p>
  
  <pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:sys="clr-namespace:System;assembly=mscorlib" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt;
  
  &lt;Grid&gt;
  &lt;ItemsControl &gt;
           &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;DockPanel LastChildFill="True"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
         &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Button DockPanel.Dock="{Binding}" Content="{Binding}"&gt;&lt;/Button&gt;
              &lt;/DataTemplate&gt;
         &lt;/ItemsControl.ItemTemplate&gt;
         &lt;sys:String&gt;Top&lt;/sys:String&gt;
            &lt;sys:String&gt;Bottom&lt;/sys:String&gt;
         &lt;sys:String&gt;Left&lt;/sys:String&gt;
         &lt;sys:String&gt;Right&lt;/sys:String&gt;
  &lt;sys:String&gt;Top&lt;/sys:String&gt;
  &lt;sys:String&gt;Top&lt;/sys:String&gt;
  &lt;sys:String&gt;Top&lt;/sys:String&gt;
      &lt;/ItemsControl&gt;
  &lt;/Grid&gt;&lt;/Page&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/KHnyl.png" alt="Here is a picture of the rendered control in xamlpad"></p>