If we can't bind a MouseBinding's Command, what are we supposed to do?
Asked Answered
F

2

5

I would love to be able to use a regular MouseBinding to capture a CTRL-Click event on my TextBlock. Unfortunately the Command property is not a dependency property and I'm using MVVM, so I can't bind it to my viewmodel.

How could Microsoft have left out this basic functionality? Are there no easy ways to detect CTRL-Clicks and bind them to a command in my viewmodel?

Filagree answered 15/9, 2009 at 14:46 Comment(0)
F
3

You could always take a look at using Attached Command Behaviours.

Fablan answered 15/9, 2009 at 14:56 Comment(0)
F
6

Originally I believe I was referring to the use of TextBlock's InputBindings member.

In .NET 4 InputsBindings now inherit from Freezable, so now the Command property is dependency property (see Binding support in InputBindings), solving the binding issue.

If you are stuck with .NET 3.5 you could create some attached properties for any type of event that you want. In your OnCommandChanged function add the event handler, and filter based on modifiers (like the Control key or the ClickCount) in your PropertyChangedCallback method.

Filagree answered 6/12, 2010 at 14:2 Comment(1)
Link is broken.Intrados
F
3

You could always take a look at using Attached Command Behaviours.

Fablan answered 15/9, 2009 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.