I'm working on project where I'm using MVVM pattern.
I have one text box:
<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" />
and label:
<Label Content="{Binding Path=LF, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="24" HorizontalAlignment="Left" Margin="540,3,0,0" Name="lbLF" VerticalAlignment="Top" Width="84" />
Here I have used two way binding with property Rspchange and LF respectively.
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"));
}
}
On model side I have this proerty like this:
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; }
}
My application is communicating through serial port to other application. I'm getting data from other application and based on that I have to update my GUI as well.
When I debugged my code I have seen that I'm getting updated value from other application to ln_frequency and bline but it's not updating my GUI.
Please tell me what is problem with my code so that It can update my GUI once I get data from other application.
P.S: code of 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();
}
}
Here my intention is to save current value of Bline and LFrequency, so that when user will launch my application again user will get latest value on GUI all time.