Input bindings

Docking/MDI for WPF Forum

Posted 8 years ago by joe
Version: 16.1.0633
Avatar

I have an issue with input bindings where a floating window won't trigger an input binding on the main window.

Example:


Main window has an input binding (CTRL+S) to save the changes made in the primary active document. Now let’s say there is a floating tool window with a property grid in it. That property grid represents some object in the primary active document. You make a change to a property and then hit (CTRL+S) to save. Nothing happens. I understand the issue because there are two windows so the message doesn't get back to the main window.
There are three options I can see:


1) Add all the input bindings to every tool panel. While this works, we are duplicating the code many times.


2) In code get the main window and copy the input commands over to the child window. This is what we have done but is a total hack. Not only that but it pukes out binding warnings before they get resolved correctly.


3) Find a way to transfer input back to the main window so it can process it. Maybe adding an owner to the tool would do the trick?
I feel like number three is the best choice. Our last docking system must have done this for us because we didn’t do anything to make this work.

 

I am open to other options.

Joe

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Joe,

That is an interesting problem to try and solve.  The reason is as you said, the floating docking windows are contained in a separate WPF Window and keyboard shortcuts don't carry across to other Windows.  Floating tool windows are already set up to be "owned" by the main Window.

We have this method defined on DockSite:

protected virtual void InitializeFloatingWindow(Window window) {}

You are able to override that method and it will fire whenever a new Window is created to host floating docking windows.  Thus that would be a perfect place to attach to a key event or add commands.  I'm curious what you think is best for your scenario.


Actipro Software Support

Posted 8 years ago by joe
Avatar

This is the code I added to that function:

protected virtual void InitializeFloatingWindow(Window window)
{
	// Copy owner window input bindings to the new window.
	Window ownerWindow = VisualTreeHelperExtended.GetAncestor<Window>(this);
	if (ownerWindow != null)
	{
		window.DataContext = ownerWindow.DataContext;
		window.InputBindings.AddRange(ownerWindow.InputBindings);
	}
}

This does work but I get a warning for every input bindind that gets copied over. These warnings only happen on initializing the first floating window. Here is what the warning looks like:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Workspace.SaveAllCommand; DataItem='MainWindowVM' (HashCode=25056856); target element is 'KeyBinding' (HashCode=40484047); target property is 'Command' (type 'ICommand')

I tried delaying it a frame to see if WPF resolves what ever it needs to but I couldn't get the warnings to go away.

 

Joe

[Modified 8 years ago]

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Joe,

It's hard to say without seeing it.  Do you mind packaging up a minimal sample that shows it happening and send that over so we can have a look?  Please email it to our support address and reference this thread in your email.  Be sure to rename the .zip file extension so it doesn't get spam blocked.  Thanks!


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.