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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:18:13+00:00 2026-06-16T16:18:13+00:00

I have this xaml code: <Window.InputBindings> <KeyBinding Command={Binding Path=KeyEnterCommand} Key=Enter /> </Window.InputBindings> and that’s

  • 0

I have this xaml code:

<Window.InputBindings>
    <KeyBinding Command="{Binding Path=KeyEnterCommand}" Key="Enter" />
</Window.InputBindings>

and that’s the Code in my ViewModel:

    private RelayCommand _keyEnterCommand;

    public ICommand KeyEnterCommand
    {
        get
        {
            if (_keyEnterCommand == null)
            {
                _keyEnterCommand = new RelayCommand(param => ExecuteKeyEnterCommand());
            }

            return _keyEnterCommand;
        }
    }

    public void ExecuteKeyEnterCommand()
    {
        // Do magic
    }

Now is my question, how can i get the sender of this command?

  • 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-16T16:18:15+00:00Added an answer on June 16, 2026 at 4:18 pm

    If by “sender” you mean the element that was focused when the key was pressed, then you can pass the currently focused element as a parameter to the command, like this:

    <Window x:Class="MyWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            x:Name="root">
        <Window.InputBindings>
            <KeyBinding Command="{Binding Path=KeyEnterCommand}"
                        CommandParameter="{Binding ElementName=root, Path=(FocusManager.FocusedElement)}"
                        Key="Escape" />
        </Window.InputBindings>
    ...
    

    private RelayCommand<object> _keyEnterCommand;
    
    public ICommand KeyEnterCommand
    {
        get
        {
            if (_keyEnterCommand == null)
            {
                _keyEnterCommand = new RelayCommand<object>(ExecuteKeyEnterCommand);
            }
    
            return _keyEnterCommand;
        }
    }
    
    public void ExecuteKeyEnterCommand(object sender)
    {
        // Do magic
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
I have this piece of XAML code: <Window x:Class=SizingTest.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Window1 Height=300 Width=300>
Im having some problems with binding in wpf/xaml. Have this simple file: <Window x:Class=test.Window1
Hi i have a xaml code like this <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml x:Class=test.Window1 x:Name=Window Title=Window1
I have this code that takes a file path that is obtained with the
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
Let's say I have this xaml code : <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Canvas> <Rectangle Name=papan
I have this XAML code that throws an exception (It just says it threw
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
I have this code in a xaml file now in a event handler code

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.