title: I can't Data Bind to a local variable in WPF/XAML
body: <p>I want a textbox to display the value of a variable when I click it (an iteration of 1 to 100), I do not know what I am doing Wrong:</p>
  
  <p>When I run the project nothing is displayed in the text box.  </p>
  
  <p>What is the best way to display variables in a text box?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  
  namespace dataBindingTest
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
  
          public string myText { get; set; }
  
          public void Button_Click_1(object sender, RoutedEventArgs e)
          {
              int i = 0;
              for (i = 0; i &lt; 100; i++)
              {
                  myText = i.ToString();
              }
          }
      }
  }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="dataBindingTest.MainWindow"
          Name="windowElement"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;Button Content="Button" HorizontalAlignment="Left" Height="106" Margin="71,95,0,0" VerticalAlignment="Top" Width="125" Click="Button_Click_1"/&gt;
          &lt;TextBlock x:Name="myTextBox" HorizontalAlignment="Left" Height="106" Margin="270,95,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="187" Text= "{Binding myText, ElementName=windowElement}" /&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>