Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Item movement from keyboard. (Read 5223 times)
Shane
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 24
Joined: Mar 26th, 2009
Item movement from keyboard.
Mar 27th, 2009 at 5:16am
Print Post  
Hi All,

I need the selected nodes on my diagram to move by pressing the directional keys on the keyboard.

The movement should be in sync of the directional key pressed.

Can someone please tell me how to do that.

Thanks,
Shane.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Item movement from keyboard.
Reply #1 - Mar 27th, 2009 at 7:27am
Print Post  
Hi Shane,

You can move the selected nodes using the method from this post:
http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=122710007...

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


I love YaBB 1G - SP1!

Posts: 24
Joined: Mar 26th, 2009
Re: Item movement from keyboard.
Reply #2 - Mar 27th, 2009 at 8:29am
Print Post  
Hi Stoyan,

Can you tell me how to map the key pressing event and the direction i.e up,down.left and right with this method.

Thanks,
Shane.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Item movement from keyboard.
Reply #3 - Mar 27th, 2009 at 11:47am
Print Post  
You could map the arrow keys like this:

RoutedUICommand cmd = new RoutedUICommand();
cmd.Text = "move left";
cmd.InputGestures.Add(new KeyGesture(Keys.Left));

CommandBinding cb = new CommandBinding(cmd, (sender, args) => MoveLeft());
CommandManager.RegisterClassCommandBinding(typeof(Diagram), cb);

Where your MoveLeft method calls MoveSelection with a Point arguments set to diagram.Selection.Bounds.TopLeft offset a few points to the left.

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


I love YaBB 1G - SP1!

Posts: 24
Joined: Mar 26th, 2009
Re: Item movement from keyboard.
Reply #4 - Mar 27th, 2009 at 1:27pm
Print Post  
Hi,

I am still not able to make it work.

The code used by me is as follows :

In window constructor :

RoutedUICommand cmd = new RoutedUICommand();
           cmd.Text = "move left";
           cmd.InputGestures.Add(new KeyGesture(Key.Left));

           CommandBinding cb = new CommandBinding(cmd, (sender, args) => MoveLeft());
           CommandManager.RegisterClassCommandBinding(typeof(Diagram), cb);
      
MoveLeft method defination :

   private void MoveLeft()
       {
           MoveSelection(new Point(diagram.Selection.Bounds.TopLeft.X+10,diagram.Selection.Bounds.TopLeft.Y) );
       }

MoveSelection method :

private void MoveSelection(Point newPosition)
       {
           Point oldPosition = diagram.Selection.Bounds.Location;
           InteractionState ist = new InteractionState(diagram.Selection, 8, MindFusion.Diagramming.Wpf.Action.Modify);
           ist.Start(oldPosition, diagram);
           ist.Update(newPosition, diagram);
           ist.Complete(newPosition, diagram);
       }

Can you please tell me what is that iam missing.

Thanks,
Shane.

  
Back to top
 
IP Logged
 
Shane
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 24
Joined: Mar 26th, 2009
Re: Item movement from keyboard.
Reply #5 - Mar 29th, 2009 at 5:43am
Print Post  
Hi,

I am still not able to make it work.

The code used by me is as follows :

In window constructor :

RoutedUICommand cmd = new RoutedUICommand();
          cmd.Text = "move left";
          cmd.InputGestures.Add(new KeyGesture(Key.Left));

          CommandBinding cb = new CommandBinding(cmd, (sender, args) => MoveLeft());
          CommandManager.RegisterClassCommandBinding(typeof(Diagram), cb); 
     
MoveLeft method defination :

   private void MoveLeft()
      {
          MoveSelection(new Point(diagram.Selection.Bounds.TopLeft.X+10,diagram.Selection.Bounds.Top Left.Y) );
      }

MoveSelection method :

private void MoveSelection(Point newPosition)
      {
          Point oldPosition = diagram.Selection.Bounds.Location;
          InteractionState ist = new InteractionState(diagram.Selection, 8, MindFusion.Diagramming.Wpf.Action.Modify);
          ist.Start(oldPosition, diagram);
          ist.Update(newPosition, diagram);
          ist.Complete(newPosition, diagram);
      }

Can you please tell me what is that iam missing.

Thanks,
Shane.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Item movement from keyboard.
Reply #6 - Mar 30th, 2009 at 8:58am
Print Post  
Hi,

Instead of

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

call

d.CommandBindings.Add(cb);

and make sure the move step is larger than GridSizeX.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Anshul
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 316
Joined: Apr 3rd, 2009
Re: Item movement from keyboard.
Reply #7 - Apr 3rd, 2009 at 8:27am
Print Post  
Hi,
I have made a handler to handle key down event. On keydown i want to move the selected item.
now problem is that, i am unable to hit the keydown event.
can anybody please tell me what is missing ?

Thanks,
Anshul
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Item movement from keyboard.
Reply #8 - Apr 3rd, 2009 at 8:34am
Print Post  
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint