I wish to bind a String with a textbox. The string is constantly being updated in a thread:
String inputread;
public event PropertyChangedEventHandler Prope
In threadFunc()
function, you set the value directly to inputread
(lower case), it's a field and have no call to OnPropertyChanged
.
You can change the code in threadFunc()
to InputRead=plc.InputImage[1].ToString();
I hope it works for you.
You need create a property and bind TextBox
to the property
private string _Inputed;
public string Inputed
{
get { return _Inputed; }
set
{
if(Equals(_Inputed, value) == true) return;
_Inputed = value;
this.OnPropertyChanged(nameof(this.Inputed));
}
}
void threadFunc()
{
try
{
while (threadRunning)
{
plc.Read();
this.Inputed = plc.InputImage[1].ToString();
}
}
catch (ThreadAbortException)
{
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
XAML
<TextBlock Text="{Binding Path=Inputed}"/>