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 8325171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:20:33+00:00 2026-06-09T00:20:33+00:00

I have a UserControl A. In the code behind file I want to raise

  • 0

I have a UserControl A.

In the code behind file I want to raise a particular event (created by me).

Now I want that the Main Window (which contains the user control) is listening to the event.

In WindowsForms i used this way:

namespace MyProgramm
{
    public partial class MyClass
    {   
        public MyClass()
        {
            InitializeComponent();
            DataContext = this;
        }

        internal event MyEventHandler MyEvent;

        private void RaiseMyEvent()
        {
            if (MyEvent!= null)
            {
                MyEvent(this, ...);
            }
        }

        public string Name { get; set; }

    }

    internal delegate void MyEventHandler (MyClass sender, ...);
}

How can I solve this in a nice way in WPF?

  • 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-06-09T00:20:34+00:00Added an answer on June 9, 2026 at 12:20 am

    In my opinion, nicer would by to use EventHandler instead of your own delegate type.

    Also, if the class is public and has a public constructor, you might make MyEvent public.

    public event EventHandler<MyEventArgs> MyEvent;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF UserControl. The code behind file declares some RoutedUICommand objects which
Background: I have a WPF UserControl (MainControl - not shown in code below) that
In The Page_Load event of an ASP.NET USercontrol, I have the following Code: If
I have a QuestionControl.ascx and a QuestionControl.ascx.cs code behind file I copied to a
I have a UserControl which rather than putting tags into its ascx markup file,
My code behind file receives an instance object Session which has a property AvailableCountries
I have a user control that has a public property defined in the code-behind
I Have usercontrol and i registered the following javascript method in code behind :
I have an UserControl and in it, a DropDownList. I'm using this code to
I have code like the following in a UserControl: Protected Overrides Sub Render(ByVal writer

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.