I am working on a small application in C # / WPF that feeds data from a serial port. It also reads a text file containing some constants in order to calculate something. An event handler handles incoming data when it arrives:
_serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Receive);
Here is the receipt handler along with the delegate that is created in the dispatcher to further update the user interface.
private delegate void UpdateUiTextDelegate(string text); private void Receive(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) {
dispatcherTimer allows you to resend commands to a device on a serial line if it cannot receive any data in a reasonable amount of time.
In addition to reading from a text file, the application has several gestures for keys defined in the designer of the main window:
public MainWindow() { InitializeComponent(); InitializeComponent(); KeyGesture kg = new KeyGesture(Key.C, ModifierKeys.Control); InputBinding ib = new InputBinding(MyCommand, kg); this.InputBindings.Add(ib); Start(); }
So, MainWindow.xaml has this command binding code:
<Window.CommandBindings> <CommandBinding Command="{x:Static custom:MainWindow.MyCommand}" Executed="MyCommandExecuted" CanExecute="CanExecuteMyCommand" /> </Window.CommandBindings>
Visual Studio Designer complains about invalid markup, but it is still used to work fine, until I started getting these errors when I started the program:
An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: 'A call to the constructor of the type “Vaernes.MainWindow” that matches the specified binding constraints threw an exception. ”Line number“ 4 ”and line position“ 9 ”.
This error appears after making minor code changes. The latter was a replacement for a text file read by a program with a different one with the same name (Add existing item ...). I searched around some online solutions, but cannot find anything similar to my problem.
I suspect this has something to do with the Dispatcher stream or input bindings. I also tried adding an exception handler and noticed that the sender was System.Windows.Threading.Dispatcher.
Anyone suggestions?