title: Window DataContext or ElementName
body: <p>I am currently facing a little problem with specifing or not specifing the datacontext of a window, and why there is a difference between various methods. Hope you can help me out.</p>
  
  <p>Lets start with some code to show my problem. This is the code behind for my TestWindow.xaml.cs, nothing really special about it just a simple string property </p>
  
  <pre><code>public partial class TestWindow : Window
  {
      private string _helloWorld = "Hello World!";
  
      public string HelloWorld
      {
          get { return _helloWorld; }
          set { _helloWorld = value; }
      }
  
      public TestWindow()
      {
          InitializeComponent();
      }
  }
  </code></pre>
  
  <p>This code will be the same for all 3 following XAML layouts, so no changes behind the code only in XAML.</p>
  
  <p>1.) Databinding with given ElementName</p>
  
  <pre><code>&lt;Window x:Class="Ktsw.Conx.ConxClient.TestWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="TestWindow" Height="300" Width="300"
          Name="TestWin"&gt;
      &lt;Grid&gt;
          &lt;TextBlock Text="{Binding HelloWorld, ElementName=TestWin}"&gt;&lt;/TextBlock&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>2.) Databinding with specifing DataContext on Window</p>
  
  <pre><code>&lt;Window x:Class="Ktsw.Conx.ConxClient.TestWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="TestWindow" Height="300" Width="300"
          DataContext="{Binding RelativeSource={RelativeSource Self}}"&gt;
      &lt;Grid&gt;
          &lt;TextBlock Text="{Binding HelloWorld}"&gt;&lt;/TextBlock&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>3.) Neither ElementName nor specifing DataContext</p>
  
  <pre><code>&lt;Window x:Class="Ktsw.Conx.ConxClient.TestWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="TestWindow" Height="300" Width="300"&gt;
      &lt;Grid&gt;
          &lt;TextBlock Text="{Binding HelloWorld}"&gt;&lt;/TextBlock&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>The first two methods work just fine, but why fails the 3rd?</p>
  
  <p>In the first method I am not specifing the DataContext and it works automatically, in the second method I am not specifing the ElementName and it works, but without declaring one of those it fails. Why would it fail getting both automatically, but work fine with getting each individually?</p>