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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:10:55+00:00 2026-06-18T03:10:55+00:00

I have this in MainWindow.xaml : <Window.InputBindings> <KeyBinding Key=O Modifiers=Control Command={Binding OpenCommand} /> <KeyBinding

  • 0

I have this in MainWindow.xaml:

<Window.InputBindings>
  <KeyBinding Key="O" Modifiers="Control" Command="{Binding OpenCommand}" />
  <KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}" />
</Window.InputBindings>

I have several child views with their own viewmodels. For instance, I have a FileView with a FileViewModel and a DataView with a DataViewModel. In both viewmodels I have an implementation of the OpenCommand:

public ICommand OpenCommand
{
    get
    {
        if (openCommand == null)
        {
            openCommand = new RelayCommand(param => this.OpenFile());
        }

        return openCommand;
    }
}

When I press Ctrl+O I want the OpenCommand command to be executed for the active view’s viewmodel. Hence, if I press the keys in my FileView, OpenFile() would be executed. If I enter the keys in my DataView, OpenData() would be executed. Sort of an MDI behavior.

The code above does not work.

How do you implement this type of keybinding/command handling?

  • 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-18T03:10:56+00:00Added an answer on June 18, 2026 at 3:10 am

    Since you have a separate implementation for the OpenCommand in FileView and DataView, you should add a KeyBinding to these views also.

    <Page.InputBindings>
        <KeyBinding Key="O" Modifiers="Control" Command="{Binding OpenCommand}" />
        <KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}" />
    </Page.InputBindings>
    

    or

    <UserControl.InputBindings>
        <KeyBinding Key="O" Modifiers="Control" Command="{Binding OpenCommand}" />
        <KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}" />
    </UserControl.InputBindings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: <Window x:Class=ScrollTest.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=450 Width=525> <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility=Visible ScrollViewer.VerticalScrollBarVisibility=Visible> <Grid>
I am puzzled by this: I have made a very simple example: MainWindow.xaml: <Window
I have a xaml file looking like this. <Window x:Class=Space4it.Energilab.DataApplicationWPF.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:sys=clr-namespace:System;assembly=mscorlib xmlns:local=clr-namespace:Space4it.Energilab.DataApplicationWPF
i have this code: <Window x:Class=WpfApplication8.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Grid> <ScrollViewer Background=#FFADB9CD
I have this xaml: <Window x:Class=WPFExample.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:WPFExample xmlns:telerik=http://schemas.telerik.com/2008/xaml/presentation Title=MainWindow Height=350 Width=525 xmlns:sys=clr-namespace:System;assembly=mscorlib>
I have this XAML code: <Window x:Class=TTT_01.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525 MouseLeftButtonDown=Window_MouseLeftButtonDown> <Canvas>
i have a window which is like this <Window x:Class=pharmacy_Concept.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350
In my MainWindow.xaml, I have the following reference to a ResourceDictionary: <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries>
In a wpf project I have this XAML code <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
In my MainWindow.xaml, I have added my UserControl to the Window. There is also

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.