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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:27:18+00:00 2026-05-16T02:27:18+00:00

In my WPF project I have a canvas on which I draw an ellipse

  • 0

In my WPF project I have a canvas on which I draw an ellipse in the XAML and add a MouseEnter event to it:

    <Canvas Width="600" Height="480" Name="canvas1" HorizontalAlignment="Left">

        <Ellipse Height="20" Width="20"  Canvas.Left="50" Canvas.Top="50" Fill="blue" Name="ellipse1" Mouse.MouseEnter="ellipse1_MouseEnter" MouseLeave ="ellipse1_MouseLeave"/>

    </Canvas>

In the codebehind I’ve got this code:

    private void ellipse1_MouseEnter(object sender, MouseEventArgs e)
    {
        ellipse1.Fill = Brushes.Red;
    }

When I enter the ellipse with my mouse, it turns red as expected.

I also have code to draw an ellipse on the canvas where I click my mouse. I have a class called Vertex in which I create a ellipse, which has a reference to the canvas.

When I instantiate a new Vertex (and so an ellipse), I add the ellipse to the canvas’ children. Before adding it to the canvas, I add a handler to the MouseEnter event:

MyEllipse.MouseEnter += new System.Windows.Input.MouseEventHandler(MyEllipse_MouseEnter);

The “MyEllipse_MouseEnter” handler looks like this:

    private void MyEllipse_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
    {
        this.MyEllipse.Fill = Brushes.Red;
    }

I expected this to work as it is the same as the first example which works.

However, when I enter the drawn ellipse with the mouse, my handler is not caleld. BUT, when go back and forth over the ellipse many times, it will eventually trigger and color the ellipse red. But this only happens on one of the many ellipses I draw, which also seems very strange.

What could be causing this strange behaviour?

  • 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-16T02:27:18+00:00Added an answer on May 16, 2026 at 2:27 am

    Solved the problem!

    When drawing the ellipse as a part of a Vertex, I add a label to the ellipse.
    Better said, I put a label on top of the ellipse:

            Canvas.SetZIndex(myEllipse, 10);
            Canvas.SetLeft(myEllipse, coordinates.X);
            Canvas.SetTop(myEllipse, coordinates.Y);
    
            Canvas.SetZIndex(myLabel, 10);
            Canvas.SetLeft(myLabel, coordinates.X - 1);
            Canvas.SetTop(myLabel, coordinates.Y - 5);
    
            canvas.Children.Add(myEllipse);
            canvas.Children.Add(myLabel);
    

    So when I clicked an ellipse on the canvas I actually clicked the label rather then the ellipse. The solution for his was simple:

            myLabel.IsHitTestVisible = false;
    

    Now the label cannot be hitted 😀

    Thx everbody!

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

Sidebar

Related Questions

I have a WPF project which compiles just fine. However, when I enable code
I have in my WPF project file RssInfo.cs in which I have public class
I have a grid in a XAML file in a WPF project. This MainGrid
In a wpf project I have this XAML code <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
In my WPF project I have a custom control which is visually represented by
I have a wpf project which uses transparent windows and I share this transparent
I have a datagrid in a WPF project. I've set the columns width to
I have a WPF project like this: In a xaml file in my RCISP.WPF
I have to write a faster canvas in wpf for my upcoming project. The
I have some storyboards in XAML (WPF Project) and I´m calling them from 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.