title: Binding datacontext to a user control using MVVM
body: <p>I have a model</p>
  
  <pre><code>    public class PersonModel : INotifyPropertyChanged
      { 
          private string _firstname;
          public string FirstName 
          { 
              get {return _firstname; }
              set { _firstname = value; RaisePropertyChanged("FirstName"); } 
          }
  
          private string _lastname;
          public string LastName
          {
              get { return _lastname; }
              set { _lastname = value; RaisePropertyChanged("LastName"); }
          } 
  
          public string FullName 
          {
              get { return string.Format("{0} {1}", FirstName, LastName); } 
          }
  
  
          protected void RaisePropertyChanged(string propertyName)
          {
              var handler = PropertyChanged;
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(propertyName));
              }
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
      } 
  </code></pre>
  
  <p>I have a viewmodel:</p>
  
  <pre><code> public class PersonViewModel
      {
          public ObservableCollection&lt;PersonModel&gt; Person { get; set; }
          public PersonViewModel()
          {
              Person = CookPersonData();
          }
  
          internal static ObservableCollection&lt;PersonModel&gt; CookPersonData()
          {
              ObservableCollection&lt;PersonModel&gt; persons = new ObservableCollection&lt;PersonModel&gt;();
              persons.Add(new PersonModel{ FirstName="Raj", LastName="kumar" });
              return persons;
          }
      }
  </code></pre>
  
  <p>The Usercontrol is </p>
  
  <pre><code>&lt;UserControl x:Class="WpfApplication1.UserControl1"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:WpfApplication1"
               mc:Ignorable="d" 
               d:DesignHeight="300" d:DesignWidth="300"&gt;
      &lt;UserControl.DataContext&gt;
          &lt;local:PersonViewModel&gt;&lt;/local:PersonViewModel&gt;
      &lt;/UserControl.DataContext&gt;
      &lt;Grid&gt;      
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition&gt;&lt;/RowDefinition&gt;
          &lt;/Grid.RowDefinitions&gt;        
          &lt;TextBlock Grid.Row="0" Text="FirstName"&gt;&lt;/TextBlock&gt;
          &lt;TextBox Text="{Binding FirstName,Mode=TwoWay}" Name="txtFirstName" Margin="115,0,0,106" DataContext="{Binding Path=Person}" Background="#FFF0F0F0" /&gt;
          &lt;TextBlock Grid.Row="1" Text="FirstName"&gt;&lt;/TextBlock&gt;
          &lt;TextBox Grid.Row="1" Text="{Binding LastName,Mode=TwoWay}" Name="txtLastName" Margin="115,0,0,110" DataContext="{Binding Path=Person}" Background="#FFF0F0F0" /&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I need to rebind the datacontext which is not happening</p>
  
  <pre><code>can you suggest what is the problem?
  </code></pre>