How to implement global copy/cut/paste functionality in a Composite WPF application?

Topics: Prism v2 - WPF 3.5
Apr 19, 2010 at 12:05 PM

So how do we implement global copy/cut/paste functionality in a Composite WPF application?

Apr 19, 2010 at 5:49 PM

.Hi,

Well you can start of by using the specific editing commands found in msdn.microsoft.com/en-us/library/system.windows.documents.editingcommands.aspx. Here is a simple cod snippet that demonstrates this:

<StackPanel>
  <Menu>
    <MenuItem Command="ApplicationCommands.Paste" />
  </Menu>
  <TextBox />
</StackPanel>

If you want something very complicated you can use a service to store and retrieve complicated objects that you copy and paste from different modules.

 

Hope this helps,

Calin

Jun 23, 2010 at 3:18 PM
Edited Jun 28, 2010 at 7:09 AM
i have seen also the following thread: http://compositewpf.codeplex.com/Thread/List.aspx?SearchText=applicationcommands I am still confused about how to use ApplicaitonCommands (such as copy, paste, properties) using MVVM? DelegateCommand is not enough in this case since ApplicationCommands have bindings to specific CanExecute and Execute. so is there a "best practice" on how to use ApplicationCommands or should i disregard them and use only DelegateCommands Thanks
Jun 28, 2010 at 7:09 AM
anyone? do you have some special way to integrate application commands? or do you just use "plain" commands?
Jun 28, 2010 at 7:31 AM
Hi, The most common method I use is the one in the stock trader reference. Here is a piece of the StockTraderRICommands class: public static class StockTraderRICommands { private static CompositeCommand submitOrderCommand = new CompositeCommand(true); public static CompositeCommand SubmitOrderCommand { get { return submitOrderCommand; } set { submitOrderCommand = value; } } } public class StockTraderRICommandProxy { virtual public CompositeCommand SubmitOrderCommand { get { return StockTraderRICommands.SubmitOrderCommand; } } } And here is how to use it: commandProxy.SubmitOrderCommand.RegisterCommand(orderCompositePresentationModel.SubmitCommand); For a deeper understanding please refer to the StockTrader implementation, Regards,
Jun 28, 2010 at 7:51 AM
Edited Jun 28, 2010 at 7:52 AM
Hi Calin thank you. I'm aware of StockTraderRICommands but i don't see how this resolves application commands: I'm more interested in Input gestures. so if one clicks ctrl+N i want to bind it to delegate/composite PRISM command as i see it now, you can make your own "New" command and use it instead of the application command - am i right? or is there another way?
Jun 30, 2010 at 1:04 PM

well, since no one has answers

 

i can just say that its possible to register using the bootstrapper something like this (its not that good but can get you started)

 

protected override System.Windows.DependencyObject CreateShell()
        {
            
            var main = new MasterDetailDefaultShell();
            
            ICommand Action1 = new DelegateCommand<string>(OnExecuteAction1, CanExecuteAction1);
            main.InputBindings.Add(new KeyBinding(Action1, new KeyGesture(Key.X, ModifierKeys.Control)));
            
            main.Show();

            return main;
        }


private void OnExecuteAction1(string str)
        {
            var r = Container.TryResolve<IEventAggregator>();
           r.GetEvent<SpecialXEventcs>().Publish("kuku");
        }


and than consume it in lower level modules