Wenn wir kein Mousebinding Command binden kann, was sollen wir tun?
-
07-07-2019 - |
Frage
Ich würde gerne eine regelmäßige MouseBinding
zu verwenden, um die Lage sein, einen zu erfassen CTRL-Click-Ereignis auf meinem TextBlock
. Leider ist die Command
Eigenschaft ist keine Abhängigkeitseigenschaft und ich bin mit MVVM, also kann ich es an meine Viewmodel nicht binden.
Wie könnte Microsoft hat diese grundlegende Funktionalität weggelassen? Gibt es keine einfache Möglichkeiten, CTRL-Klicks und binden sie auf einen Befehl in meinem Viewmodel?
erkennenLösung
You could always take a look at using Attached Command Behaviours.
Andere Tipps
Originally I believe I was referring to the use of TextBlock
's InputBindings
member.
In .NET 4 InputsBinding
s 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.