title: Simple Binding of Data from code behind to XAML
body: <p><br/>  I am new to WPF concepts. I want to just display a string in a textbox. I tried the following C# code and XAML to bind a string to a TextBox.Text property.
  C# code:</p>
  
  <pre><code>public partial class Window1 : Window
  {
      public int TmpVal;
      public string TmpStr;
  
       public Window1()
      {
          TmpVal = 50;
          TmpStr = "Windows Created";
          InitializeComponent();
          this.DataContext = this;
      }
      private void viewButton_Click(object sender, RoutedEventArgs args)
      {
          TmpStr = "Button clicked";
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>XAML:</p>
  
  <pre><code> &lt;Window x:Class="TestWPF.Window1"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="600" Width="800" x:Name="ThisWindow"&gt;
  &lt;Grid&gt;
      &lt;TextBox Name="txtTest1" Margin="200,0,200,200" HorizontalAlignment="Left" Height="50" Width="200" Text="{Binding TmpStr, ElementName=ThisWindow}" /&gt;
      &lt;Button Name="butTest1"  Click="viewButton_Click"&gt;Test123&lt;/Button&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>On execution I always get blank text in my textbox (even when I invoke the click event).
  <br/> I browsed through the stackoverflow site but couldn't solve the problem (though many questions were close to this one)
  <br/> Can someone suggest me if anything is overlooked or missed out?</p>