我遇到了一个小问题,我尝试在 Blazor 服务器项目的页面上显示实时数据。阅读了几篇文章后,我认为这应该可以使用 INotifyPropertyChanged 来实现。不幸的是我对此很菜鸟,这是我尝试过的:
我的模型价格与 INotifyPropertyChanged (使用 Rider 生成):
public class Price : INotifyPropertyChanged
{
private double _askPrice;
private double _bidPrice;
private double _spread;
public Price(double askPrice, double bidPrice)
{
_askPrice = askPrice;
_bidPrice = bidPrice;
}
public double AskPrice {
get => _askPrice;
set
{
_askPrice = value;
OnPropertyChanged("AskPrice");
OnPropertyChanged("Spread");
}
}
public double BidPrice
{
get => _bidPrice;
set
{
_bidPrice = value;
OnPropertyChanged("BidPrice");
OnPropertyChanged("Spread");
}
}
public double Spread => _askPrice - _bidPrice;
public event PropertyChangedEventHandler …Run Code Online (Sandbox Code Playgroud)