I am a c# sharp beginner and my first project is a terminal application for the serial port. The incoming data are ascii characters and they come with 115 kbaud.
Now I want to bind each incoming line to a wpf text box. In my serial port class I use IPropertyChanged events and I succeeded in binding each incoming line to the textbox. But it's not satisfying just to see one line, the content of the textbox should be appended with each incoming line. I don't want to collect the strings in my serial port class and just send them all again with each new one. I tried and the result was very slow.
Next I tried to use the binding event TargetUpdated to use textbox.AppendText(incomingline)...
<TextBox
Name="textBoxIncoming"
Text="{Binding Path=Incoming, Mode=OneWay, NotifyOnTargetUpdated=True}"
DataContext="{Binding NotifyOnTargetUpdated=True}"
IsReadOnly="True"
TargetUpdated="textBoxIncoming_TargetUpdated"
... />`
The result was that each incoming line is displayed twice in the text box, the lines before are cleared.
Does anybody know, how to append text to a textbox with wpf binding?
This cannot be done with a binding alone. Instead, create a List where you add all lines that you receive. Modify the Incoming property to return string.Join(Environment.NewLine, listOfReceivedStrings).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.