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

Pan while mouse over container shape

1 Answer 56 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 29 Sep 2014, 08:47 AM
I've already changed the diagram's activetool to the pan tool, but this does not seem to take affect when the mouse is over a container shape, some of my container shapes are very large, and I don't really need the capability to select them, so is it possible to make the mouse pan while over a container shape?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 01 Oct 2014, 12:58 PM
Hello Alex,

Indeed, when the mouse is over a container or a shape, the selection behavior have bigger precedence then the ActiveTool. However, you can achieve your requirement using a custom PointerTool. 

Here are few snippets that demonstrates such approach:
var toolService = this.diagram.ServiceLocator.GetService<IToolService>() as ToolService;
toolService.ToolList[0] = new MyPointerTool();
toolService.ActivateTool(MyPointerTool.ToolName);

public class MyPointerTool : PointerTool
{
    public override bool MouseDown(PointerArgs e)
    {
        var result = base.MouseDown(e);
        if (this.HitItem != null && this.DontLikeHitItem())
            this.HitItem = null;
 
        return result;
    }
 
    private bool DontLikeHitItem()
    {
        return !MyProperties.GetCanSelect(this.HitItem as FrameworkElement);
    }
}
 
public static class MyProperties
{
    public static readonly DependencyProperty CanSelectProperty =
        DependencyProperty.RegisterAttached("CanSelect", typeof(bool), typeof(MyProperties), new PropertyMetadata(true));
 
    public static bool GetCanSelect(DependencyObject obj)
    {
        return (bool)obj.GetValue(CanSelectProperty);
    }
 
    public static void SetCanSelect(DependencyObject obj, bool value)
    {
        obj.SetValue(CanSelectProperty, value);
    }
}

<telerik:RadDiagramContainerShape local:MyProperties.CanSelect="false">

For your convenience I also attached a sample project with this implementation. I hope it helps.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Diagram
Asked by
Alex
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or