title: WPF: template or UserControl with 2 (or more!) ContentPresenters to present content in 'slots'
body: <p>I am developing LOB application, where I will need multiple dialog windows (and displaying everything in one window is not an option/makes no sense).</p>
  
  <p>I would like to have a user control for my window that would define some styling, etc., and would have <strong>several</strong> slots where content could be inserted - for example, a modal dialog window's template would have a slot for content, and for buttons (so that user can then provide a content and set of buttons with bound ICommands).</p>
  
  <p>I would like to have something like this (but this doesn't work):</p>
  
  <p>UserControl xaml:</p>
  
  <pre><code>&lt;UserControl x:Class="TkMVVMContainersSample.Services.Common.GUI.DialogControl"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
      &gt;
      &lt;DockPanel&gt;
          &lt;DockPanel 
              LastChildFill="False" 
              HorizontalAlignment="Stretch" 
              DockPanel.Dock="Bottom"&gt;
              &lt;ContentPresenter ContentSource="{Binding Buttons}"/&gt;
          &lt;/DockPanel&gt;
          &lt;Border 
              Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
              Padding="8"
              &gt;
              &lt;ContentPresenter ContentSource="{Binding Controls}"/&gt;
          &lt;/Border&gt;
      &lt;/DockPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Is something like this possible? How should I tell VS that my control exposes two content placeholders so that I can use it like this?</p>
  
  <pre><code>&lt;Window ... DataContext="MyViewModel"&gt;
  
      &lt;gui:DialogControl&gt;
          &lt;gui:DialogControl.Controls&gt;
              &lt;!-- My dialog content - grid with textboxes etc... 
              inherits the Window's DC - DialogControl just passes it through --&gt;
          &lt;/gui:DialogControl.Controls&gt;
          &lt;gui:DialogControl.Buttons&gt;
              &lt;!-- My dialog's buttons with wiring, like 
              &lt;Button Command="{Binding HelpCommand}"&gt;Help&lt;/Button&gt;
              &lt;Button Command="{Binding CancelCommand}"&gt;Cancel&lt;/Button&gt;
              &lt;Button Command="{Binding OKCommand}"&gt;OK&lt;/Button&gt;
               - they inherit DC from the Window, so the OKCommand binds to MyViewModel.OKCommand
               --&gt;
          &lt;/gui:DialogControl.Buttons&gt;
      &lt;/gui:DialogControl&gt;
  
  &lt;/Window&gt;
  </code></pre>
  
  <p>Or maybe I could use a ControlTemplate for a window <a href="https://stackoverflow.com/questions/420538/how-to-make-a-template-window-in-wpf">like here</a>, but then again: Window has only one content slot, therefore its template will be able to have only one presenter, but I need two (and if in this case it would po maybe possible to go with one, there are other use cases where several content slots would come hand, just think about a template for article - control's user would supply a title, (structured) content, author name, image...).</p>
  
  <p>Thank you!</p>
  
  <p>PS: If I wanted to just have buttons side by side, how can I put multiple controls (buttons) to StackPanel? ListBox has ItemsSource, but StackPanel has not, and it's Children property is read-only - so this doesn't work (inside the usercontrol):</p>
  
  <pre><code>&lt;StackPanel 
      Orientation="Horizontal"
      Children="{Binding Buttons}"/&gt; 
  </code></pre>
  
  <p>EDIT: I don't want to use binding, as I want to assign a DataContext (ViewModel) to a whole window (which equals View), and then bind to it's commands from buttons inserted into control 'slots' - so any use of binding in the hierarchy would break inheritance of View's DC.</p>
  
  <p>As for the idea of inheriting from HeaderedContentControl - yes, in this case it would work, but what if I want three replacable parts? How do I make my own "HeaderedAndFooteredContentControl" <strong>(or, how would I implement HeaderedContentControl if I didn't have one)</strong>? </p>
  
  <p><strong>EDIT2: OK, so my two solutions doen't work - this is why:</strong>
  The ContentPresenter gets it's content from the DataContext, but I need the bindings on contained elements to link to original windows' (UserControl's parent in logical tree) DataContext - because this way, when I embed textbox bound to ViewModel's property, it is not bound, as <em>the inheritance chain has been broken inside the control</em>!</p>
  
  <p>It seems that I would need to save parent's DataContext, and restore it to the children of all control's containers, but I don't get any event that DataContext up in the logical tree has changed.</p>
  
  <p><strong>EDIT3: I have a solution!</strong>, deleted my previous aswers.
  See my response.</p>