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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:37:15+00:00 2026-05-20T03:37:15+00:00

I have an .NET 4.0 application using Caliburn.Micro. I want to create a dynamic

  • 0

I have an .NET 4.0 application using Caliburn.Micro. I want to create a dynamic menu such that I don’t need to write XAML code for each menu item. Additionally, I want to associate each command with a key gesture.

I have an interface IAction:

public interface IAction
{
    string Name { get; }
    InputGesture Gesture { get; }
    ICommand Command { get; }      
}

In my ViewModel I expose a list of IActions:

private List<IAction> _actions;
public List<IAction> Actions
{
    get { return _actions; }
    set
    {
        _actions = value;
        NotifyOfPropertyChange(()=> Actions);
    }
}

I bind my Toolbar to the actions as follows:

<ToolBar>
    <Menu ItemsSource="{Binding Actions}">
        <Menu.ItemContainerStyle>
            <Style TargetType="MenuItem">
                <Setter Property="Header" Value="{Binding Name}" />
                <Setter Property="Command" Value="{Binding Command}" />
            </Style>
        </Menu.ItemContainerStyle>
    </Menu>
</ToolBar>

All of the above works.

What I’m missing is the databinding of the Key Gesture.

Everywhere I read, I only find examples with static definitions of Window.InputBindings such as:

<Window.InputBindings>
  <KeyBinding Key="B" Modifiers="Control" Command="ApplicationCommands.Open" />
</Window.InputBindings>

It would be great if I simply could encapsulate the Window.InputBindings in an ItemsControl, but that doesn’t work.

Any of you know how to dynamically bind Window.InputBindings?

Thanks!

  • 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-20T03:37:15+00:00Added an answer on May 20, 2026 at 3:37 am

    Key gestures have to be created for the window object (if they are to have window-wide effect).

    I guess you could create a custom derived window object which would have a dependency property named for example BindableInputBindings. This property in its OnChanged callback would add/remove the key bindings every time the source collection changed.

    EDIT: There may be some errors.

    public class WindowWithBindableKeys: Window {
    
        protected static readonly DependencyProperty BindableKeyBindingsProperty = DependencyProperty.Register(
            "BindableKeyBindings", typeof(CollectionOfYourKeyDefinitions), typeof(WindowWithBindableKeys), new FrameworkPropertyMetadata("", new PropertyChangedCallback(OnBindableKeyBindingsChanged))
        );
    
        public CollectionOfYourKeyDefinitions BindableKeyBindings
        {
            get
            {
                return (string)GetValue(BindableKeyBindingsProperty);
            }
            set
            {
                SetValue(BindableKeyBindingsProperty, value);
            }
        }
    
        private static void OnBindableKeyBindingsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as WindowWithBindableKeys).InputBindings.Clear();
    
            // add the input bidnings according to the BindableKeyBindings
        }
    
    }
    

    Then in XAML

    <mynamespace:WindowWithBindableKeys BindableKeyBindings={Binding YourSourceOfKeyBindings} ... > ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET client application that needs to communicate with a server using
I have to develop an application using C#.net that has to be run once
I have a web application using ASP.NET 2.0 and I want to know if
I have a small VB.NET application that I'm working on using the full version
I am using asp.net MVC to develop an application that will have ajax interactions.
I have a .NET application that makes calls to a native Win32 DLL using
I have an ASP.NET application that authenticates users using Ldap against active directory. This
I have a .NET application, which is using an open source C++ compression library
I have a control application - using asp.net webservices. I have a timer which
I have a pretty standard table set-up in a current application using the .NET

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.