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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:57:58+00:00 2026-05-13T21:57:58+00:00

I have a WPF app that is using the MVVM pattern. Hooking up buttons

  • 0

I have a WPF app that is using the MVVM pattern. Hooking up buttons to the VM is pretty straight forward since they implement the ICommand. I have a context menu that works similar. The next step is to create shortcut keys for the context menu. I can’t figure out how to get the shortcut key invoke the Command. Here is an example:

<MenuItem Header="Update" Command="{Binding btnUpdate}" >
    <MenuItem.Icon>
        <Image Source="/Images/Update.png"
               Width="16"
               Height="16" />
        </MenuItem.Icon>
    </MenuItem>

now I’ve added this:

<Window.InputBindings>
    <KeyBinding Key="U"
                Modifiers="Control" 
                Command="{Binding btnUpdate}" />
</Window.InputBindings>

to try and connect the shortcut keys to the same binding, but this doesn’t work. The error is:

Error 169 A ‘Binding’ cannot be set on the ‘Command’ property of type ‘KeyBinding’. A ‘Binding’ can only be set on a DependencyProperty of a DependencyObject.

Isn’t there a way to hook up this event to the Command? I can’t figure this out.

thanks in advance!

Bill

  • 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-13T21:57:59+00:00Added an answer on May 13, 2026 at 9:57 pm

    I wrote a custom markup extension to “bind” InputBindings to commands, which can be used almost like a real binding :

    <UserControl.InputBindings>
        <KeyBinding Modifiers="Control" 
                    Key="E" 
                    Command="{input:CommandBinding EditCommand}"/>
    </UserControl.InputBindings>
    

    Note that this markup extension uses private reflection, so it can only be used if your application runs in full trust…

    Another option is to use the CommandReference class. It can be found in the MVVM toolkit available here. It’s probably a cleaner approach, but a bit more complex to use.

    Note that in WPF 4, the InputBinding.Command, InputBinding.CommandParameter and InputBinding.CommandTarget properties are dependency properties, so they can be bound normally

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

Sidebar

Ask A Question

Stats

  • Questions 327k
  • Answers 327k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From ActiveRecord association's perspective, any model with belongs_to declaration has… May 14, 2026 at 1:50 am
  • Editorial Team
    Editorial Team added an answer You could do something like this with jQuery: $((function(){ $('#navigation… May 14, 2026 at 1:50 am
  • Editorial Team
    Editorial Team added an answer if(isset($_POST['submit'])); 1) Should not have a semicolon after it. 2)… May 14, 2026 at 1:50 am

Related Questions

In a WPF app that I'm writing using the MVVM pattern, I have a
I'm looking for some input for a challenge that I'm currently facing. I have
My name is Jesús from Spain, I'm a .NET developer and I just discovered
I'm using the MVVM pattern in my first WPF app and have a problem
I am developing a WPF app using MVVM and need some help. for the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.