user3160134
user3160134

Reputation: 199

Add MouseLeftButtonUp events dynamically

I've added the following 2 methods to the MainWindow.xml, but I can't fire the event

private void Button_Click_2(object sender, RoutedEventArgs e)
{
    lstContacts.Items.Clear();
    cvMenuItem test = new cvMenuItem("test", Environment.GetEnvironmentVariable("USERPROFILE") + @"\Downloads\images.jpg");
    test.MouseLeftButtonUp += new System.EventHandler(imClicked);
    lstContacts.Items.Add(test);
}

void imClicked(object sender, EventArgs e)
{
    MessageBox.Show("hello");
}

I keep getting this error, why?

Cannot implicitly convert type 'System.EventHandler' to 'System.Windows.Input.MouseButtonEventHandler' MainWindow.xaml.cs 64 39 WpfApplication1

Upvotes: 0

Views: 508

Answers (1)

yo chauhan
yo chauhan

Reputation: 12295

Try this

test.MouseLeftButtonUp += imClicked;


private void imClicked(object sender, MouseButtonEventArgs e)
    {
             MessageBox.Show("hello");
    }

Upvotes: 1

Related Questions