Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 580221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:26:59+00:00 2026-05-13T14:26:59+00:00

How can I pass the event handler TextBlock_MouseDown_Test1 or TextBlock_MouseDown_Test2 to SmartGrid so that

  • 0

How can I pass the event handler TextBlock_MouseDown_Test1 or TextBlock_MouseDown_Test2 to SmartGrid so that the TextBlocks which it creates will execute this event handler when they are clicked?

The code below gets the error:

The best overloaded method match for
‘TestDel234.SmartGrid.SmartGrid(TestDel234.Window1,
System.Collections.Generic.List,
System.EventHandler)’ has some invalid
arguments

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;

namespace TestDel234
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            List<string> items = new List<string> { "one", "two", "three" };
            SmartGrid sg = new SmartGrid(this, items, TextBlock_MouseDown_Test1);
        }

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

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

    public class SmartGrid
    {
        public SmartGrid(Window1 window, List<string> items, EventHandler eventHandler)
        {
            foreach (var item in items)
            {
                TextBlock tb = new TextBlock();
                tb.Text = item;
                tb.MouseDown += new MouseButtonEventHandler(eventHandler);
                window.MainContent.Children.Add(tb);
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:27:00+00:00Added an answer on May 13, 2026 at 2:27 pm

    You can’t cast your mouse button event args handler to a plain EventHandler – try an EventHandler<MouseButtonEventArgs> in the constructor instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I pass args to the event handler function? This runs the function
How can I pass some data from a Global.asax event handler to a custom
How can I pass custom data to the jQuery event handler, specifically from the
I use such code to pass arguments to event handler functions. But, in this
I want to a pass local object to the event handler. How can I
I have an <input> which has an onkeydown inline event handler. In this handler,
You can pass special strings into jQuery's Datepicker class setDate() method like +7 which
I know that I can pass a string as the second parameter to the
Is there any way that I can pass arguments in selector? example: I have
I know from here that I can pass an ignore option in the jQuery.validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.