title: WPF: Binding a Label to a class property
body: <p>I'm trying to get the content of a label to bind to the string property of a class instance without much success. </p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window x:Class="WPFBindingTest.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="300" Width="300"&gt;    
  &lt;Grid&gt;        
      &lt;Label Height="28" Margin="12,55,106,0" Name="label1" Background="Bisque"
             Content="{Binding Source=MyFoo, Path=W1}" VerticalAlignment="Top" /&gt;
  
      &lt;Label Height="28" Margin="12,12,106,0" Name="label2" Background="Bisque"
             Content="{Binding Source=MyFoo, Path=W2}"  VerticalAlignment="Top" /&gt;
  
      &lt;Button Height="23" HorizontalAlignment="Right" Margin="0,0,32,48"
              Name="button1" VerticalAlignment="Bottom" Width="89"
              Click="button1_Click"&gt;
          Set Properties
      &lt;/Button&gt;
  
  &lt;/Grid&gt;   
  &lt;/Window&gt;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>namespace WPFBindingTest
  {
     public partial class Window1 : Window
      {
          public Foo MyFoo;
  
          public Window1()
          {
              InitializeComponent();            
  
              MyFoo = new Foo();           
          }
  
          private void button1_Click(object sender, RoutedEventArgs e)
          {      
              MyFoo.W1 = "Hello";
              MyFoo.W2 = "Dave";
          }
      }
  
      public class Foo
      {
          public string W1 { get; set; }
          public string W2 { get; set; }
      }
  }
  </code></pre>
  
  <p>i.e. when I click the button, I set the properties of MyFoo to "Hello" and "Dave", and want that reflected in the labels on the UI. I've set the Content as a binding but something isn't right. What am I doing wrong here? </p>