title: Why DataBinding is not propagating to UserControl
body: <p>This morning I asked a question <a href="https://stackoverflow.com/questions/39835222/command-binding-is-not-propagating-for-control-into-a-datatemplate-of-itemtempla?noredirect=1#comment66965701_39835222">here</a> and doing a simple working sample gave me a different behavior than expected.</p>
  
  <p>Full working sample at <a href="https://github.com/EricOuellet2/CommandRoutingIntoItemTemplate" rel="nofollow noreferrer">GitHub</a>. Main partial code below.</p>
  
  <p>In this present case, the command is never propagated to any UserControl, either if the UserControl is use directly as a child of the Window. It also not work if the UserControl is used as a DataTemplate for a ListBox ItemTemplate.</p>
  
  <p>I also include a hack button to fix the problem where the Command reach the UserControls. The hack come from <a href="https://stackoverflow.com/questions/24099274/menuitem-in-window-commandbinding-in-usercontrol">StackOverflow</a>. </p>
  
  <p>But using the hack does not explain why UserControl does not receive the Command (without it) and using this hack also break the first rule of good coding: "Hi cohesion and Low coupling". The hack should be used in the the window code in order for it to manage the Command in the UserControl, my thought is that it should happen by default. </p>
  
  <p>Why the command is not propagating by default to the UserControl and what should I do to propagate the command to the UserControl in a clean way?</p>
  
  <p>Note: Using only one CommandBinding (removing one or the other) in the UserControl does not fix the problem .</p>
  
  <p>Partial code:</p>
  
  <pre><code>&lt;Window x:Class="CommandRoutingIntoItemTemplate.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:CommandRoutingIntoItemTemplate"
          xmlns:system="clr-namespace:System;assembly=mscorlib"
          mc:Ignorable="d"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition Height="Auto"&gt;&lt;/RowDefinition&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;local:UserControlTest&gt;&lt;/local:UserControlTest&gt;
  
          &lt;ListBox Grid.Row="1"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Border BorderBrush="Aqua" BorderThickness="2"&gt;
                          &lt;local:UserControlTest&gt;&lt;/local:UserControlTest&gt;
                      &lt;/Border&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
  
              &lt;ListBox.Items&gt;
                  &lt;system:String&gt;1&lt;/system:String&gt;
                  &lt;system:String&gt;2&lt;/system:String&gt;
              &lt;/ListBox.Items&gt;
          &lt;/ListBox&gt;
  
          &lt;StackPanel Grid.Row="2" Orientation="Horizontal"&gt;
              &lt;Button Command="local:Commands.CommandTest"&gt;Put focus on TestBlock and click here to see if command occurs&lt;/Button&gt;
              &lt;Button Click="AddHack"&gt;Hack&lt;/Button&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>UserControl: </p>
  
  <pre><code>&lt;UserControl x:Class="CommandRoutingIntoItemTemplate.UserControlTest"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:CommandRoutingIntoItemTemplate"
               mc:Ignorable="d" 
               d:DesignHeight="300" d:DesignWidth="300"&gt;
      &lt;UserControl.CommandBindings&gt;
          &lt;CommandBinding Command="local:Commands.CommandTest" CanExecute="CommandTestCanExecuteUserControl" Executed="CommandTestExecuteUserControl"&gt;&lt;/CommandBinding&gt;
      &lt;/UserControl.CommandBindings&gt;
      &lt;Grid&gt;
          &lt;TextBox Text="UserControlTest"&gt;
              &lt;TextBox.CommandBindings&gt;
                  &lt;CommandBinding Command="local:Commands.CommandTest" CanExecute="CommandTestCanExecuteTextBox" Executed="CommandTestExecuteTextBox"&gt;&lt;/CommandBinding&gt;
              &lt;/TextBox.CommandBindings&gt;
          &lt;/TextBox&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>