Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding Cut/Copy/Paste commands to rehosted designer in MVVM app
    primarykey
    data
    text
    <p>I'm rehosting the WF4 workflow designer in a custom MVVM WPF application, along the lines of Maurices <a href="http://msmvps.com/blogs/theproblemsolver/archive/2009/12/23/rehosting-the-workflow-designer-in-wf4.aspx" rel="nofollow noreferrer">excellent blog post</a></p> <p>But I could not figure out how to bind the application commands like Cut, Copy, Paste, Undo, Redo (which I want to expose in a main menu) to the designer. The keyboard bindings like Ctrl-X work out of the box, but I want to have my MenuItems do the same. Any help here?</p> <p>Selecting Edit->Copy in the main menu bar should copy the currently selected activity to the clipboard, just like Ctrl-C does. Is that possible at all?</p> <hr> <p><em>Edit 1:</em></p> <p>If I simply add the general application commands like</p> <pre><code>MenuItem Header="Cu_t" Command="Cut" /&gt; </code></pre> <p>I get a menu with always disabled items:</p> <p><img src="https://i.stack.imgur.com/UC24t.png" alt="Screenshot"></p> <hr> <p><em>Edit 2:</em></p> <p>The general command binding seems to be ok. If I select some text in a textbox (somewhere outside the designer surface in my application, or even inside an activity), the menu items get enabled and work as expected:</p> <p><img src="https://i.stack.imgur.com/3elxB.png" alt="Selected text"> --> <img src="https://i.stack.imgur.com/XCt2w.png" alt="enter image description here"></p> <p>But if I select the activity as a whole and want to cut/copy.. it, the menu items are all dimmed - although the keyboard bindings work as expected, and in the builtin context menu the items are enabled:</p> <p>Context menu: </p> <p><img src="https://i.stack.imgur.com/FBhl0.png" alt="Context menu"> </p> <p>But the main menu: </p> <p><img src="https://i.stack.imgur.com/KycXz.png" alt="Main menu"></p> <p>So it is not a general problem with the menu items, it is strictly related to the workflow designer. On <a href="http://msdn.microsoft.com/en-us/library/system.windows.input.applicationcommands.copy.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.input.applicationcommands.copy.aspx</a> we can read</p> <blockquote> <p>When the CommandTarget is not set, the target for the command is the element which has keyboard focus. If the element which has keyboard focus does not support the Paste command or cannot currently execute the paste command (the clipboard is empty, for example) then the MenuItem would be grayed out.</p> </blockquote> <p>In this situation, the workflow designer has the focus, and Cut could be performed, but still grayed out. Does this mean that the workflow designer does not support application commands at all?</p> <hr> <p><em>Edit 3:</em></p> <p>Another extremely weird finding. I added the "Delete" Command to the menu, and this one <strong>does</strong> get enabled when an activity is selected. Clicking this menu item indeed deletes the activity from the designer surface. </p> <pre><code>&lt;MenuItem Header="_Delete" Command="Delete" /&gt; </code></pre> <p>So it is completely inconsistent with the Cut/Copy/past commands...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload