小编Jea*_*yee的帖子

C# Blazor 服务器:使用 INotifyPropertyChanged 显示实时数据

我遇到了一个小问题,我尝试在 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)

c# asp.net inotifypropertychanged blazor blazor-server-side

3
推荐指数
1
解决办法
4547
查看次数