Filter what can and can't be pasted

2 posts, 0 answers
  1. Joost
    Joost avatar
    8 posts
    Member since:
    Feb 2015

    Posted 11 Feb Link to this post


    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

  2. Dinko
    Dinko avatar
    182 posts

    Posted 16 Feb Link to this post

    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)
            // 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.

    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
  3. DevCraft banner
Back to Top