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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:47:56+00:00 2026-06-01T00:47:56+00:00

I am working on a WPF MVVM application. It has a custom canvas class

  • 0

I am working on a WPF MVVM application. It has a custom canvas class inheriting from Canvas. There is a window with one of these custom canvas placed (using XAML) and it’s background colour set to Transaparent. Graphics are drawn to the Canvas using DrawingVisuals to draw primitive shapes and add them as Visual children to the Visual tree. This works and renders my shapes to the screen.

I have added a mouse up event to the Canvas in the Window code behind. This fires when I click anywhere on the canvas except on the line of a drawn visual or on the coloured area of a filled shape. To be clear:

  • If I click outside the drawn shape i.e. on the background of the
    canvas it fires.
  • If there is an unfilled rectangle and I click on the inside blank
    area then the mouse up fires.
  • If I click on the rectangle’s border line it does not.
  • If I click inside a filled rectangle it does not.

From http://msdn.microsoft.com/en-us/library/ms742254.aspx#providing_hit_testing_support
it appears like this should work though I am using the Canvas MouseUp event as it does not have a MouseLeftButtonUp event. In the MS example they don’t use a Canvas but talk about a “host container” but I’m not sure if that’s relevant.

How can I get the events to fire when clicking on a DrawingVisual? Why is the event surpressed when clicking inside a drawn area but not outside it?

Thanks

  • 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-01T00:47:57+00:00Added an answer on June 1, 2026 at 12:47 am

    I have solved the problem. The canvas has a RootNode dependency property which the ViewModel sets. The problem is when you add any children to a canvas then you need to call AddVisualChild(child) and AddLogicalChild(child). I had to add a property changed callback to the dependency property so it could call the two methods to add them as visual and logical children otherwise it doesn’t understand the parent child relationships which screws up user input.

    Thanks for you time everyone. Sorry if I never provided enough details. It’s a big app so was trying to include only relevant info.

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

Sidebar

Related Questions

I'm working on a WPF MVVM application and I've got a TextBox on my
I am new to WPF and MVVM, and I am working on an application
I'm working on a WPF application, and I'm structuring it using the MVVM pattern.
I'm building a WPF application and working with the MVVM pattern. I have 4
I am working on a WPF application with MVVM, but am not using any
I m working in a WPF MVVM Project and I am using one Wpf
I am working on my first WPF/MVVM application, and I have come across a
I'm working on an WPF application using the mvvm-light framework. I'm new to both
I have a WPF application using MVVM that utilises TreeViewItemViewModels to simplify working with
I'm currently working on a WPF application that uses MVVM. I've got a ListBox

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.