WPF-MVVM, Master - Detail datagrid with calculated column. Rate * Quantity = Total
<p>I have data entry form bound to viewmodel. I follow EF code-first approach and the details tables are represented by observable collections in my models, like below.</p>

<pre><code>public partial class item
{ 
    public item()
    {
        orders = new ObservableCollection&lt;order&gt;();
    }
}
</code></pre>

<p>Everything works fine but in few cases I have a master entry with a detail in the form of grid. Here's xaml part which binds SelectedItem.Orders to detail grid.</p>

<pre><code>&lt;UserControl x:Class="ABCD.Views.itemView"
    ....
    DataContext="{Binding itemMaster, Source={StaticResource Locator}}"
    Height="Auto" Width="Auto"&gt;
    &lt;Grid&gt; 
        &lt;Grid.ColumnDefinitions.... /&gt;
        &lt;Grid.RowDefinitions..../&gt;
        &lt;DataGrid AutoGenerateColumns="False" VerticalAlignment="Top" ItemsSource="{Binding items}" SelectedItem="{Binding SelectedItem}" Name="dgitems" HorizontalAlignment="Stretch" RowDetailsVisibilityMode="VisibleWhenSelected" &gt;
             &lt;DataGrid.Columns&gt;
                        &lt;DataGridTextColumn x:Name="ItemNameColumn" Binding="{Binding Path=ItemName}" Header="Item Name" Width="125" /&gt;
                        &lt;DataGridTextColumn x:Name="ItemCodeColumn" Binding="{Binding Path=ItemCode}" Header="Item Code" Width="75" /&gt;
                        &lt;DataGridTextColumn x:Name="StockColumn" Binding="{Binding Path=StockLevel}" Header="Stock" Width="60" /&gt;
             &lt;/DataGrid.Columns&gt;
        &lt;/DataGrid&gt;
        &lt;Label Grid.Column="3" Grid.Row="0" Margin="3,3,3,3" Content="Item Code"      VerticalAlignment="Center" /&gt;
        &lt;TextBox Grid.Column="4" Grid.Row="0" HorizontalAlignment="Left" Margin="3,3,3,3" Name="ctrlItemCode" Text="{Binding Path=SelectedItem.ItemCode, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Width="120" Height="Auto" VerticalContentAlignment="Center" /&gt;
        &lt;Label Grid.Column="3" Grid.Row="2" Margin="3,3,3,3" Content="Product Name" VerticalAlignment="Center" /&gt;
        &lt;TextBox Grid.Column="4" Grid.Row="2" HorizontalAlignment="Left" Margin="3,3,3,3" Name="ctrlProductName" Text="{Binding Path=SelectedItem.ItemName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Width="120" Height="Auto" VerticalContentAlignment="Center" /&gt;
        &lt;DataGrid Grid.Column="2" Grid.Row="16" Grid.ColumnSpan="3"  Height="145" AutoGenerateColumns="False" VerticalAlignment="Top" ItemsSource="{Binding SelectedItem.Orders}"  Name="dgOrders" HorizontalAlignment="Stretch" &gt;
             &lt;DataGrid.Columns&gt;
                  &lt;DataGridTemplateColumn Width="120"&gt;
                       &lt;DataGridTemplateColumn.CellTemplate&gt;
                            &lt;DataTemplate&gt;
                                 &lt;ComboBox DisplayMemberPath="OrderNumber" SelectedValuePath="OrderId"  ItemsSource="{Binding Path=DataContext.Orders,   RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" SelectedValue="{Binding Path=OrderId}" /&gt;
                             &lt;/DataTemplate&gt;
                        &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;
                  &lt;DataGridTextColumn x:Name="QtyColumn" Binding="{Binding Path=Quantity}" Header="Qty" Width="75" /&gt;
                  &lt;DataGridTextColumn x:Name="PriceColumn" Binding="{Binding Path=Price}" Header="Price" Width="75" /&gt;
                  &lt;DataGridTextColumn x:Name="TotalColumn" Binding="{Binding Path=Total}" Header="Total" Width="75" /&gt;
              &lt;/DataGrid.Columns&gt;
        &lt;/DataGrid&gt;
   &lt;/Grid&gt;
 &lt;/UserControl&gt;
</code></pre>

<p>In such cases, I want to calculate the total as soon as the user types price and quantity in the grid. I know it can be handled if we have related property in viewmodel. But in my case, the Orders is a collection in item model.</p>

<p>Thanks in advance.</p>