简体   繁体   中英

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.

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.

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).

This triggered the focused control (starting the Wizard) again after closing the wizard.

Thanks to @JeffRSon and @dymanoid

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.

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