title: C# Data Binding via code behind doesn't work for Text property in TextBox
body: <p>I have a textbox with xaml markup like this: <br>
  <code>&lt;TextBox x:Name="txtHN" Text="{Binding Path=AN}"/&gt;</code></p>
  
  <p>The above code works perfectly well. But when i change the data binding implementation from XAML to code-behind, It does not work anymore. The following code-behind does not work anymore: <br></p>
  
  <pre><code>Binding textHnBinding = new Binding();
  textHnBinding.Path = new PropertyPath("AN");
  txtHN.SetBinding(TextBox.TextProperty, textHnBinding);
  </code></pre>
  
  <p>I had set the <code>textbox.datacontext</code> to the same collectionviewsource but the code-behind version does not work anymore. I had really no idea what seems to be the culprit.</p>
  
  <p>I use the following code for the CVS.source:</p>
  
  <pre><code>                IEnumerable&lt;decimal&gt; ANListWard4 = (from s in context.IPDAN
                                                      where ward.Contains(s.CURRENTWARD)
                                                      select s.AN).Distinct().OrderBy(n =&gt; n);
                  List&lt;IPDAN&gt; Ward4AN = new List&lt;IPDAN&gt;();
                  foreach (decimal d in ANListWard4)
                  {
                      IPDAN ward4AN1 = new IPDAN();
                      ward4AN1.AN = d;
                      Ward4AN.Add(ward4AN1);
                  }
  </code></pre>
  
  <p>I set the CVS.Source to Ward4AN. There was no instance where the Ward4AN was null, or has no data. </p>