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

  • Home
  • SEARCH
  • 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 8434811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:45:36+00:00 2026-06-10T06:45:36+00:00

I have a simple program that implements code discussed in this question to trace

  • 0

I have a simple program that implements code discussed in this question to trace mouse movements. However, it seems that the events are only fired if the background colour of the Canvas control is set.

XAML (with the background colour set):

<Window x:Class="SimplePaint.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="501" Width="784">
    <Grid>
        <Canvas Height="402" HorizontalAlignment="Left" Margin="12,12,0,0" Name="PaintCanvas" VerticalAlignment="Top" Width="738" MouseDown="PaintCanvas_MouseDown" MouseMove="PaintCanvas_MouseMove" MouseUp="PaintCanvas_MouseUp" Background="#FFDEF4FF">
            <Polyline x:Name="polyline" Stroke="Black" StrokeThickness="3"/>
        </Canvas>
    </Grid>
</Window>

C#:

private bool drawing = false;

private void PaintCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
    this.drawing = true;
}

private void PaintCanvas_MouseMove(object sender, MouseEventArgs e)
{
   if (this.drawing)
        polyline.Points.Add(e.GetPosition(this.PaintCanvas));
}

private void PaintCanvas_MouseUp(object sender, MouseButtonEventArgs e)
{
    this.drawing = false;
}

This code works. However, if I remove Background="#FFDEF4FF" from the XAML, nothing happens when the program is used. Setting a breakpoint in the event handlers reveals that they do not fire.

  • 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-10T06:45:37+00:00Added an answer on June 10, 2026 at 6:45 am

    Have you tried “Transparent” for the Background….otherwise your Background=null (i.e. has no background)…and the HitTesting logic of WPF doesn’t hit your object.

    For an explanation see here:

    • {x:Null} vs. Transparent?

    • http://agsmith.wordpress.com/2008/09/16/hit-testing-in-wpf/

    • http://msdn.microsoft.com/en-us/library/ms752097.aspx

    • Hit testing child controls added to a canvas does not work

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

Sidebar

Related Questions

I have this simple program that computes salaries for four different worker types. It's
This is my source code. I'trying to implement a simple program that asks a
Say I have simple program that emulates a board game with a number of
I have a simple program that checks webpages for strings, example: Private Sub Button1_Click(ByVal
I have a simple program that creates a thread, loops twenty times and then
I have a simple program that reads data from a PNG into a 2D
I have a simple python program that I'd like to daemonize. Since the point
I have a simple forms program that I have been fighting with for a
I have a simple Delphi program that I'm working on, in which I am
Well, i have written a simple python program that parses HTML with HTMLParser. Here

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.