简体   繁体   English

Button_click事件再次无故触发(涉及条形码读取器)

[英]Button_click event fired again without reason (Barcode reader involved)

Im showing a Wizard upon click on a button in code behind. 我点击后面代码中的按钮后显示向导。

private void Button_Click(object sender, RoutedEventArgs e)
{
     Wizard myWizard = new Wizard();
     myWizard.ShowDialog();    
     if (myWizard.DialogResult != true)   
     {
         return;
     }
}

The wizard window is passed as a parameter in a command 向导窗口作为命令中的参数传递

void Switch2NextPage(object CallerWindow)
{
    WizardWindow = (System.Windows.Window)CallerWindow;
}     

In the ViewModel of the wizard i'm trying to close the Dialog if in a textfield a specific text is entered. 如果在文本字段中输入了特定的文本,则在向导的ViewModel中,我试图关闭对话框。

public string OrderNr
{
    get
    {
        return _OrderNr;
    }
    set
    {
        _OrderNr = value;
        if (Orders.FirstOrDefault((order) => order.OrderNr == value) != null)
        {
            myNewOrder = Orders.FirstOrDefault((order) => order.OrderNr == value);
            WizardWindow.DialogResult = true;
            WizardWindow.Close();
        }
        myNewOrder.OrderNr = value;
        RaisePropertyChanged("OrderNr");
    }
}

The dialog gets closed, somehow the click-event of the button is fired again. 对话框关闭,以某种方式再次触发了按钮的单击事件。

Callstack shows only "external code" and the clickhandler. Callstack仅显示“外部代码”和clickhandler。

I have no idea how to handle this. 我不知道该如何处理。

Any help appreciated! 任何帮助表示赞赏!

The involved barcode reader sent not only the code number, but also another CrLf (enter key). 所涉及的条形码读取器不仅发送了代码号,还发送了另一个CrLf(输入密钥)。

This triggered the focused control (starting the Wizard) again after closing the wizard. 关闭向导后,这又触发了集中控制(启动向导)。

Thanks to @JeffRSon and @dymanoid 感谢@JeffRSon和@dymanoid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM