title: SL4. Binding by ElementName is not working within DataTemplate
body: <p>There is an another headache with DataTemplate.</p>
  
  <p><br><strong>Description:</strong>
  Using Silverlight 4, Mvvm, etc. (standart set of developer tools for Silverlight LOB applications).
  <br></p>
  
  <p>List of entities is succesfully binded to <code>DataGrid</code>. One property (nullable bool BoolValue) is responsible for entity behavior and presented in datagrid with picture, clicking on wich leads to changing visibility of some Controls within LayoutRoot element.</p>
  
  <p><strong>Problem:</strong>
  The problem is that, unfortunately or fortunately, <strong><code>ElementName</code> binding within <code>DataTemplate</code> does not see other elements except those, that are placed within this template.</strong></p>
  
  <p><strong>Code Sample:</strong></p>
  
  <pre><code>&lt;navigation:DataGridTemplateColumn Width="40"
                                CanUserReorder="True"
                                CanUserSort="False"&gt;
       &lt;navigation:DataGridTemplateColumn.CellTemplate&gt;
            &lt;DataTemplate&gt;
               &lt;Border Background="GhostWhite"&gt;
               &lt;Grid&gt;
                &lt;Image x:Name="ImageWithTrigger"
                       Grid.Column="1"
                       Margin="10,4,0,0"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Cursor="Hand"
                       Source="images/someImage.png"
                       Stretch="None"
                       Visibility={Binding BoolValue, Converter={StaticResource boolToVisibilityConverter} }&gt;
                 &lt;i.Interaction.Triggers&gt;
                   &lt;i:EventTrigger EventName="MouseLeftButtonDown"&gt;
                       &lt;AttachedBehaviors:TrickyBehavior FrameworkElementToHide="{Binding ElementName=FirstControlOutside}" 
                                                         FrameworkElementToShow="{Binding ElementName=SecoundControlOutside}"/&gt;
                   &lt;/i:EventTrigger&gt;
                &lt;/i:Interaction.Triggers&gt;
              &lt;/Grid&gt;
              &lt;/Border&gt;
            &lt;/DataTemplate&gt;
       &lt;/navigation:DataGridTemplateColumn.CellTemplate&gt;
  &lt;/navigation:DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>In the example above, FrameworkElementToHide and FrameworkElementToShow are always null.</p>
  
  <p>There are a lot of pretty similar problems and solutions in internet, but I have not found any straightforward and elegant way of solving this problem.</p>