straku
straku

Reputation: 23

How to disable possibility to select particular child of InkCanvas?

I'm using InkCanvas and I'm trying to disable selection for its particular child. InkCanvas children collection consists of Eliipse and Path objects and I want to disable possibility to select all of the Path objects. I was trying to achieve it by checking if mouse hit specific object in PreviewMouseLeftButtonDown event handler:

private void myCanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
        Point downPosition = e.GetPosition(myCanvas);
        UIElement element = myPath;
        if (myCanvas.InputHitTest(downPosition) == element) e.Handled = true;
}

Now I know that it won't work because InputHitTest function returns InkCanvas selection adorner, if I click on the object one more time, when it is already selected above function works (at least InputHitTest is returning object that interests me). Do you have any idea how to make this work?

Upvotes: 1

Views: 351

Answers (1)

pushpraj
pushpraj

Reputation: 13679

So far what I can see is that you want particular child of inkcanvas not be selected when clicking on canvas

so assuming you have a path called myPath

private void InkCanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    Point downPosition = e.GetPosition(myPath);
    if (myPath.InputHitTest(downPosition) == myPath) 
        e.Handled = true;
}

so directly do hit test on the path and see if it return itself then you can determine a click on the path and then by setting e.Handled = true you make the event consumed hence the element will not be selected.

alternate approach will be testing with null, this will have the same behavior as above, so depends on choice

    if (myPath.InputHitTest(downPosition) != null) 
        e.Handled = true;

I propose the above solution based on assumption, you please correct me if this is not what you are looking for.

Upvotes: 1

Related Questions