小编Mor*_*rty的帖子

PresentationFramework.dll中发生未处理的"System.Windows.Markup.XamlParseException"类型异常

我正在使用C#/ WPF中的一个小应用程序,该应用程序由来自串行端口的数据提供.它还会读取包含一些常量的文本文件,以便计算某些内容.事件处理程序在到达时处理传入的数据:

_serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Receive);
Run Code Online (Sandbox Code Playgroud)

这是Receive处理程序,以及在Dispatcher中创建的委托,以进一步更新UI.

private delegate void UpdateUiTextDelegate(string text);

private void Receive(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
    // collect characters received to our 'buffer' (string)
    try
    {
        // stops long running output timer if enabled
        if (dispatcherTimer.IsEnabled)
        {
            dispatcherTimer.Stop();
        }

        message = _serialPort.ReadLine();

        dispatcherTimer.Start();
        Dispatcher.Invoke(DispatcherPriority.Send, new UpdateUiTextDelegate(updateUI), message);
    }
    catch (Exception ex)
    {
        // timeout                
        dispatcherTimer.Start();
        SerialCmdSend("SCAN");
    }            
}
Run Code Online (Sandbox Code Playgroud)

dispatcherTimer允许重发命令给单元上的串行线路,如果它未能得到在合理的时间量的任何数据.

除了还从文本文件中读取外,应用程序还在主窗口的构造函数中定义了一些键盘快捷键手势:

public MainWindow()
{
    InitializeComponent();
    InitializeComponent();

    KeyGesture kg = new KeyGesture(Key.C, ModifierKeys.Control);
    InputBinding ib = new …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml dispatcher

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

dispatcher ×1

wpf ×1

xaml ×1