How to display data in WPF datagrid in MVVM
<p>My xaml code    </p>

<pre><code>&lt;Window x:Class="SampleWPFApp.View.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viewmodel="clr-namespace:SampleWPFApp.ViewModel"
        Title="Window1" Height="500" Width="500"&gt;
    &lt;Window.Resources&gt;
        &lt;viewmodel:FirstPageViewModel x:Key="fp"&gt;&lt;/viewmodel:FirstPageViewModel&gt;
    &lt;/Window.Resources&gt;
&lt;Grid&gt;
    &lt;TextBox HorizontalAlignment="Left" Height="23" Margin="75,38,0,0" TextWrapping="Wrap" Text="{Binding FirstName, Source={StaticResource fp}}" VerticalAlignment="Top" Width="120"/&gt;
    &lt;TextBox HorizontalAlignment="Left" Height="23" Margin="75,79,0,0" TextWrapping="Wrap" Text="{Binding LastName, Source={StaticResource fp}}" VerticalAlignment="Top" Width="120"/&gt;
    &lt;Button Content="Add" HorizontalAlignment="Left" Margin="104,118,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.093,1.636" Command="{Binding acomm, Source={StaticResource fp}}" /&gt;
    &lt;DataGrid HorizontalAlignment="Left" Name="mydatagrid" Margin="47,194,0,0" VerticalAlignment="Top" Height="178" Width="385" ItemsSource="{Binding Path=MyDataGrid,Mode=TwoWay,NotifyOnSourceUpdated=True,NotifyOnTargetUpdated=True}" DataContext="{DynamicResource fp} " Loaded="DataGrid_Loaded"/&gt;
&lt;/Grid&gt;
</code></pre>

<p>My property where grid is bound to in ViewModel,</p>

<pre><code>private List&lt;Employee&gt; mysampleGrid;
public List&lt;Employee&gt; MySampleGrid
{
    get
    {
        return mysampleGrid;
    }
    set
    {
        mysampleGrid = value;
        OnPropertyChanged("MySampleGrid");
    }
}
</code></pre>

<p>Method called when button is clicked in ViewModel,</p>

<pre><code>public void AddDataToDb()
{            

    e.FirstName = FirstName;
    e.LastName = LastName;
    context.Employees.Add(e);
    context.SaveChanges();
    this.MySampleGrid = null;

    //Setting List to value from database after inserting into db
    MySampleGrid = context.Employees.Where(x =&gt; x.FirstName != null).ToList();

}
</code></pre>

<p>But even after setting value of list(which is bound to datagrid) from database grid is not getting updated/refreshed in UI.please help. i have implemented INotifyPropertyChanged interface also.</p>