button1.PerformClick() in wpf

后端 未结 7 1647
难免孤独
难免孤独 2020-12-15 21:07

Why this code in WPF does not work ?

private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show(\"yes\");
    }
    pr         


        
7条回答
  •  鱼传尺愫
    2020-12-15 21:59

    I think the shortest and most efficient solution to your problem would be simply done in one line.

    button1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
    

    That should work for WPF C#

提交回复
热议问题