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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:19:32+00:00 2026-05-29T12:19:32+00:00

I have a very interesting task that I need help with. The description is

  • 0

I have a very interesting task that I need help with. The description is as follows:

I have a user control (SomeUserControl), that I am using in a Main Window. I write my application entirely on SomeUserControl, and Main Window is hosting SomeUserControl and nothing else.

Right now I have a shutdown button (in SomeUserControl), that is supposed to close the Main Window. The reason for this is that I do not want anything from SomeUserControl to close the application itself, but to fire an event from SomeUserControl, and Main Window receives it, and Main Window will close the application instead of SomeUserControl.

How do I do it? I am not familiar with the concept of creating and handling custom events, so if someone could explain it in words and in code as an example, I will be very grateful to you!

Edit: Here’s my code so far.

(in Window 2)

Public Event CloseApp As EventHandler

Private Sub CancelButton_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CancelButton.Click
    DialogResult = False
    RaiseEvent CloseApp(Me, New EventArgs)
End Sub

(In Main Window)
Public loginPage As New LoginPage

Public Sub New()
    InitializeComponent()
    AddHandler loginPage.CloseApp, AddressOf Me.ShutDownJobChangeWindow
End Sub

Private Sub ShutDownJobChangeWindow(ByVal sender As Object, ByVal e As EventArgs)
    Application.Current.Shutdown()
End Sub

Goal: I want to close the application when I click cancel in Window 2, but I don’t want to do it in such a way that Window 2 closes itself, but by sending some notification to Main Window, and Main Window closes the application.

  • 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-29T12:19:33+00:00Added an answer on May 29, 2026 at 12:19 pm

    If the logic of the user control is implemented in the “code behind” of the user control class, do the following.

    I’m assuming the XAML file has somewhere a button with a click event:

    <Button Click="Button_Click">Close App</Button>
    

    Then, in your code behind for SomeUserControl class, do the following:

    public partial class SomeUserControl : UserControl
    {
        public event EventHandler CloseApp;
    
        ...
    
        private void Button_Click( object sender, RoutedEventArgs e )
        {
            if( CloseApp != null ) {
                CloseApp( this, new EventArgs( ) );
            }
        }
    }
    

    In your Main window, listen to the event:

    ...
    
    someUserCtrl.CloseApp += new EventHandler( MyFn );
    
    private void MyFn( object sender, object EventArgs e ) {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have very simple problem. I need to create model, that represent element of
Here is one very interesting problem. I am using SQL Server 2008. I have
I have a very interesting LINQ question. I have a document, that I am
I have a very interesting task, which I don't know how to implement. I
I have one very interesting question (for me :) ).. I'm using jquery and
I have just seen a very interesting user interface widget . This widget explains
On Railcasts I have noticed a very interesting feature 'Go to symbol' window. It
I have a very interesting problem on my LinqToSql model. On some of my
I've seen jint in Codeplex. It looks very interesting. Have you used it? Is
I have very little experience building software for Windows, and zero experience using the

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.