8,757
社区成员
发帖
与我相关
我的任务
分享首先是xml代码
<TextBlock Text="{Binding SNR}" FontSize="34" TextAlignment="Center"/>
<TextBlock Grid.Row="1" Text="{Binding FLD}" FontSize="34" TextAlignment="Center"/>
页面的后台也写了this.DataContext = new MonitorViewModel();
public class MonitorViewModel : NotifyBase, IProtocolData
{
private double snr;
public double SNR
{
get { return snr; }
set { snr = value; this.NotifyChanged(); }
}
private double fld;
public double FLD
{
get { return fld; }
set { fld = value; this.NotifyChanged(); }
}
public bool Translate(string[] arrayMsg, string srcText)
{
SNR = Convert.ToInt32(arrayMsg[10]);
FLD = Convert.ToInt32(arrayMsg[11]);
System.Diagnostics.Debug.WriteLine("解析到场强" + FLD);
return true;
}
}
解析到场强这一句,一直能在后台输出,但是view界面就是不更新,下面是通知类。这是为什么?感谢感谢
public class NotifyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyChanged([CallerMemberName] string propName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}