Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Keyboard focus for ApplicationCommands (Read 1744 times)
GregC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Jan 16th, 2014
Keyboard focus for ApplicationCommands
Apr 25th, 2014 at 10:21am
Print Post  
Hi,

We are overriding the ApplicationCommand key bindings for such things as Cut, Copy + Paste....

CommandManager.RegisterClassCommandBinding(typeof(DiagramPage), cb);

These are attached to DiagramPage. This works fine, i.e. recieves the event, after the page gets the focus when the user left clicks it.

The problem is when the page first shows (by setting DiagramView.Diagram = myDiagramPage) I cannot force the KeyboardFocus on to the diagram programmatically.

Any ideas how to do it ? I tried. Keyboard.Focus(_myDiagramPage); but it gets ignored.

I think that MF must set the focus somehow before raising the DiagramPage.MouseDown event, as when i catch the event the DiagramPage already has the keyboard focus.

Thanks
Greg
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Keyboard focus for ApplicationCommands
Reply #1 - Apr 25th, 2014 at 11:20am
Print Post  
Hi,

If you are using setup similar to the one shown in MultiViews sample project, try setting the focus from first LayoutUpdated event:

Code
Select All
bool firstRun = true;
Diagram diagram;

private void Window_Loaded(object sender, RoutedEventArgs e)
{
	var view = new DiagramView();
	diagram = new Diagram();
	diagram.Factory.CreateShapeNode(30, 30, 60, 60).Selected = true;

	var window = new UI.Wpf.Window();
	window.Width = 200;
	window.Height = 200;
	window.Content = view;
	window.Show(windowHost);

	view.Focusable = false;
	view.Diagram = diagram;

	Keyboard.Focus(diagram); // does not work from here

	LayoutUpdated += window_LayoutUpdated;
}

void window_LayoutUpdated(object sender, EventArgs e)
{
	if (firstRun)
	{
		Keyboard.Focus(diagram);
		firstRun = false;
	}
} 



It seems Keyboard.Focus does not work until the first WPF layout pass has run, and calling it from LayoutUpdated works.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
GregC
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: Jan 16th, 2014
Re: Keyboard focus for ApplicationCommands
Reply #2 - Apr 25th, 2014 at 12:24pm
Print Post  
Thanks Stoyan, that does the trick.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint