Binding 如何刷新绑定到DataGrid的只读属性

Binding 如何刷新绑定到DataGrid的只读属性,binding,refresh,readonly,wpfdatagrid,Binding,Refresh,Readonly,Wpfdatagrid,具有只读TotalPrice属性的Order类,该属性根据该类的其他属性进行计算。通过ObservableCollection,我绑定到DataGrid。代码如下 订单类 public class Order { public String Name { get; set; } public Double Price { get; set; } public Int32 Quantity { get; set; } public Double TotalPrice

具有只读TotalPrice属性的Order类,该属性根据该类的其他属性进行计算。通过ObservableCollection,我绑定到DataGrid。代码如下

订单类

public class Order
{
    public String Name { get; set; }
    public Double Price { get; set; }
    public Int32 Quantity { get; set; }
    public Double TotalPrice { get { return Price * Quantity; } }
}
DataGrid的XAML代码

<!--DataGrid-->
<my:DataGrid AutoGenerateColumns="False" Name="dgOrders" ItemsSource="{Binding}">
    <my:DataGrid.Columns>
        <my:DataGridTextColumn Binding="{Binding Name}" Header="Name" IsReadOnly="True" />
        <my:DataGridTextColumn Binding="{Binding Price}" Header="Price" IsReadOnly="True" />
        <my:DataGridTextColumn Binding="{Binding Quantity}" Header="Quantity"  />
        <my:DataGridTextColumn Binding="{Binding Total, Mode=OneWay}" Header="Total" IsReadOnly="True" />
    </my:DataGrid.Columns>
</my:DataGrid>

将类绑定到DataGrid

ObservableCollection<Order> Orders = new ObservableCollection<Order>();

Orders.Add(new Order() { Name = "Book", Quantity = 1, Price = 13 });
Orders.Add(new Order() { Name = "Pencil", Quantity = 2, Price = 4 });
Orders.Add(new Order() { Name = "Pen", Quantity = 1, Price = 2 });

dgOrders.DataContext = Orders;
ObservableCollection订单=新的ObservableCollection();
添加(新订单(){Name=“Book”,数量=1,价格=13});
添加(新订单(){Name=“Pencil”,数量=2,价格=4});
添加(新订单(){Name=“Pen”,数量=1,价格=2});
dgOrders.DataContext=订单;
现在,当用户更新DataGrid TotalPrice列上的Quantity列时,应该更新TotalPrice属性本身。我的消费是,因为TotalPrice没有更新,所以它不会像其他属性那样生成通知,所以datagrid不会更新

谢谢你的评论

编辑:让我澄清我的问题

我需要一种通知系统,当只读属性由于内部更改而发生更改时,通知UI更新自身