This is a migrated thread and some comments may be shown as answers.

Filter what can and can't be pasted

1 Answer 84 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Joost
Top achievements
Rank 1
Joost asked on 11 Feb 2016, 03:52 PM

Hi,

I use the RadDiagram to show a program flow. It works well, but I'd like to filter which content can and can't be pasted.
For example, certain custom shapes should only occur once in the flow.
Is there a way to disallow some items to be pasted?

Kind regards

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 16 Feb 2016, 02:19 PM
Hello Joost,

Thank you for contacting us.

In order to achieve your requirement, you can override the Paste command of RadDiagram in the static constructor of your main window.
static MainWindow()
{
    var pasteBinding = new CommandBinding(DiagramCommands.Paste, ExecutePaste, CanExecutePaste);
    CommandManager.RegisterClassCommandBinding(typeof(RadDiagram), pasteBinding);
}
 
private static void CanExecutePaste(object sender, CanExecuteRoutedEventArgs e)
{
    var diagram = sender as RadDiagram;
    if (diagram != null)
    {
        e.CanExecute = true;
    }
}
You can implement your logic in the ExecutePaste handler and it should look something like this:
private static void ExecutePaste(object sender, ExecutedRoutedEventArgs e)
{
    var diagram = sender as RadDiagram;
    if (diagram == null) return;
  
    if (you want to paste in the currently selected container)
    {
        diagram.Paste();
    }
    else
    {
        // Do nothing.
    }
}
Note that in RadDiagram you can paste any information coming from your Clipboard and you might have to consider that fact while implementing your logic. For your convenience, we have prepared a sample project demonstrating this approach.

Please, give this project a try and let us know if this works for you.

Regards,
Dinko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Diagram
Asked by
Joost
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or