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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:16:34+00:00 2026-06-12T10:16:34+00:00

I am relatively newbie. The problem I have is a simple one I think,

  • 0

I am relatively newbie. The problem I have is a simple one I think, but I cant find a solution. Clicking on button1 opens a popup and adds to canvas1 a MouseDown event handler canvas1.MouseDown += (s1, e1) =>{...}; I want to remove this when the user closes the popup. Here’s the whole code:

namespace MyfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            int linesNumber = 0;

            Button button1 = new Button();
            button1.Content = "Draw";
            button1.HorizontalAlignment = HorizontalAlignment.Left;
            button1.VerticalAlignment = VerticalAlignment.Top;
            button1.Click += (s, e) =>
            {
                Popup popup = new Popup();
                popup.PlacementTarget = button1;
                popup.IsOpen = true;

                Button closePopupButton = new Button();
                closePopupButton.Content = "close";
                closePopupButton.Click += (s1, e1) =>
                {
                    popup.IsOpen = false;
                    // remove canvas1.MouseDown event handler here
                };
                popup.Child = closePopupButton;

                canvas1.MouseDown += (s1, e1) =>
                {
                    Point point = Mouse.GetPosition(canvas1);
                    Line line = new Line();
                    line.X2 = point.X; line.Y2 = point.Y;
                    line.Stroke = Brushes.Red; line.StrokeThickness = 1;
                    canvas1.Children.Add(line);
                    linesNumber++;
                };
            };
            grid1.Children.Add(button1);
        }
    }
}
  • 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-12T10:16:35+00:00Added an answer on June 12, 2026 at 10:16 am

    save the eventhandler somewhere in a variable

    MouseButtonEventHandler onMousedown = (o, args) => 
    { 
        ...
    };
    
    canvas1.MouseDown += onMouseDown;
    

    and later you can remove the eventhandler again:

    canvas1.MouseDown -= onMouseDown;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively(read: stupid newbie) familiar with disassembly but this bit stumped me: I have
I'm a newbie to WCF, trying to perform relatively simple task. I'm trying to
I'm a relative newbie on iPhone app development but have successfully created a tab
EDITED WITH NEW CODE BELOW I'm relatively newbie on Multithreading but to achieve my
I think I searched for an answer about my problem but I did not
I'm relatively a newbie, would appreciate help :) I am looking to find entry(ies)
I am relatively new to the WCF world so my applogies for the newbie
Just a simple question from a relative Java newbie: what is the difference between
Relatively new to rails, I'm working on a simple rails app for a few
Relatively new to WinForms but I'm working on a small business app. Anyway, where

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.