Avoid deselecting currently selected shape while clicking on the diagram

7 posts, 1 answers
  1. Laurent Kempé
    Laurent Kempé avatar
    8 posts
    Member since:
    Dec 2005

    Posted 07 Jan 2013 Link to this post

    Hi

    I would like to avoid deselecting currently selected shape while clicking on the diagram.
    When you click on the diagram, out of a shape, the currently selected shape is deselected.
    I couldn't find a way to configure or do that.
    Thanks for your help.

    Cheers
    Laurent Kempé
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Jan 2013 Link to this post

    Hi Laurent,

     The code below uses the MouseLeftButtonDown event of the RadDiagram, checks whether the clicked element is the RadDiagram and if yes, prevents the selection:

    public partial class MainWindow : Window
        {
            private bool shouldPreventSelection = false;
            public MainWindow()     
            {          
                InitializeComponent();
            }
     
            private void diagram_PreviewSelectionChanged_1(object sender, SelectionChangedEventArgs e)
            {
                if (this.shouldPreventSelection)
                {
                    e.Handled = true;
                    this.shouldPreventSelection = false;
                }
            }
     
            private void diagram_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
            {
                var element = this.diagram.InputHitTest(e.GetPosition(this));
                if( element != null && element.GetType() == typeof(DiagramSurface))
                {
                    this.shouldPreventSelection = true;
                }
            }
        }
    Let us know if the suggested approach is suitable for you. 

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 07 Jan 2013 Link to this post

    Hello Laurent,

     This is ok if we don't use Rectangle Selection. Have you considered using it?  What is the expected behavior that you wish to achieve when using it ?

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Laurent Kempé
    Laurent Kempé avatar
    8 posts
    Member since:
    Dec 2005

    Posted 07 Jan 2013 Link to this post

    Hi Petar,

    Thanks it works correctly after changing this line

                var element = rootDiagram.InputHitTest(e.GetPosition(rootDiagram));  //replacing the this

    I don't know why I didn't found the PreviewSelectionChange and seen only the SelectionChange event. Maybe I was reading too much the doc which mention only Selectionchanged on http://www.telerik.com/help/wpf/raddiagrams-events-diagram.html and should have searched more in the code.

    Never the less know it works the way I want, so thank you!

    Cheers
    Laurent Kempé
  6. Laurent Kempé
    Laurent Kempé avatar
    8 posts
    Member since:
    Dec 2005

    Posted 07 Jan 2013 Link to this post

    Hi Petar ,

    Yeah I don't use it so it is fine!

    Cheers
    Laurent Kempé
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Jan 2013 Link to this post

    Hi Laurent,

    We're happy that the suggested solution works for you. Also, I'd like to thank you for notifying us about the documentation issue - we now added the PreviewSelectionChanged event description in the events article and the change will be reflected with the next upload of the online documentation.

    I updated your Telerik points for this feedback.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Laurent Kempé
    Laurent Kempé avatar
    8 posts
    Member since:
    Dec 2005

    Posted 07 Jan 2013 Link to this post

    Hi Tina

    Thanks
Back to Top
UI for WPF is Visual Studio 2017 Ready