【发布时间】:2023-03-29 07:45:01
【问题描述】:
我正在开发使用 MVVM 模式的项目。
我有一个文本框:
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,30,72,0" Name="textBox1"
Text="{Binding Path=Rspchange, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" VerticalAlignment="Top" Width="75" />
和标签:
<Label Content="{Binding Path=LF, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="24" HorizontalAlignment="Left" Margin="540,3,0,0" Name="lbLF" VerticalAlignment="Top" Width="84" />
这里我分别使用了属性 Rspchange 和 LF 的两种方式绑定。
public UInt16 Rspchange
{
get
{
return this.eObj.GetRsBaseline(this.index);
}
set
{
this.eObj.SetRsBaseline(value, this.Index);
this.OnPropertyChanged(new PropertyChangedEventArgs("Rspchange"));
this.eObj.writedata(DefaultFileName);
}
}
public string LF
{
get
{
return this.eObj.LFrequency;
}
set
{
this.eObj.LFrequency = value;
this.OnPropertyChanged(new PropertyChangedEventArgs(" LF"));
}
}
在模型方面,我有这样的属性:
public override string LFrequency
{
get { return configObject.lnFrequency.ToString(); }
set { configObject.lnFrequency = Convert.ToByte(value); }
}
public override UInt16 GetRsBaseline(int channelIndex)
{
return (byte)this.configObject.CConfig[index].Bline;
}
public override void SetRsBaseline(UInt16 value, int index)
{
byte[] arr = BitConverter.GetBytes(value);
this.configObject.CConfig[index].Bline = arr[0];
}
public byte Bline
{
get { return this.bline; }
set { this.bline = value; }
}
public byte lnFrequency
{
get { return this.ln_frequency; }
set { this.ln_frequency = value; }
}
我的应用程序正在通过串行端口与其他应用程序通信。我正在从其他应用程序获取数据,因此我还必须更新我的 GUI。
当我调试我的代码时,我发现我正在从其他应用程序获取更新值到 ln_frequency 和 bline,但它没有更新我的 GUI。
请告诉我我的代码有什么问题,以便在我从其他应用程序获取数据后更新我的 GUI。
P.S:writexmldata的代码
public void WriteXmlData(string path)
{
if ((ie.Current as XElement).Attribute("name").Value == "Bline")
{
(ie.Current as XElement).Attribute("value").Value = this.channel_config[0].Bline.ToString();
}
if ((ie.Current as XElement).Attribute("name").Value == "LFrequency")
{
(ie.Current as XElement).Attribute("value").Value = this.lnFrequency.ToString();
}
}
这里我的意图是保存 Bline 和 LFrequency 的当前值,以便当用户再次启动我的应用程序时,用户将始终在 GUI 上获得最新值。
【问题讨论】:
标签: xml wpf xaml mvvm inotifypropertychanged