none
Make InkCanvas lines *not* selectable RRS feed

Answers

  • Hi,

    Seems you're looking at a Silverlight sample, well, it's not quite exactly the same as WPF. Besides, in that sample, Stefan is actually using InkPresenter, not InkCanvas.

    So in your case, you may do something like this:

    <Canvas x:Name="cvsGrid" Loaded="cvsGrid_Loaded" Height="400" Width="400">
        <InkCanvas x:Name="inkCanvas" EditingMode="Select" 
                   Canvas.Left="0" Canvas.Top="0" Height="400" Width="400" />
    </Canvas>
    

    And the code for cvsGrid_Loaded:

    private void cvsGrid_Loaded(object sender, RoutedEventArgs e)
    {
        double cellSize = 25d;
        for (double x1 = cellSize; x1 < inkCanvas.ActualWidth; x1 += cellSize)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Color.FromArgb(64, 0, 0, 255));
            line.IsHitTestVisible = false;
            line.X1 = x1;
            line.X2 = x1;
            line.Y1 = 0d;
            line.Y2 = inkCanvas.ActualHeight;
            cvsGrid.Children.Add(line);
        }
        for (double y1 = cellSize; y1 < inkCanvas.ActualHeight; y1 += cellSize)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Color.FromArgb(64, 0, 0, 255));
            line.IsHitTestVisible = false;
            line.X1 = 0d;
            line.X2 = inkCanvas.ActualWidth;
            line.Y1 = y1;
            line.Y2 = y1;
            cvsGrid.Children.Add(line);
        }
    }
    

    The basic idea is to have a Canvas in the back of the InkCanvas to actually hold the grid lines (so the lines aren't added to the InkCanvas and thus can't be selected).

    Hope this helps.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    • Marked as answer by usabilitytank Saturday, January 2, 2010 7:51 PM
    Tuesday, December 29, 2009 11:06 AM
    Moderator

All replies

  • Hi,

    Seems you're looking at a Silverlight sample, well, it's not quite exactly the same as WPF. Besides, in that sample, Stefan is actually using InkPresenter, not InkCanvas.

    So in your case, you may do something like this:

    <Canvas x:Name="cvsGrid" Loaded="cvsGrid_Loaded" Height="400" Width="400">
        <InkCanvas x:Name="inkCanvas" EditingMode="Select" 
                   Canvas.Left="0" Canvas.Top="0" Height="400" Width="400" />
    </Canvas>
    

    And the code for cvsGrid_Loaded:

    private void cvsGrid_Loaded(object sender, RoutedEventArgs e)
    {
        double cellSize = 25d;
        for (double x1 = cellSize; x1 < inkCanvas.ActualWidth; x1 += cellSize)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Color.FromArgb(64, 0, 0, 255));
            line.IsHitTestVisible = false;
            line.X1 = x1;
            line.X2 = x1;
            line.Y1 = 0d;
            line.Y2 = inkCanvas.ActualHeight;
            cvsGrid.Children.Add(line);
        }
        for (double y1 = cellSize; y1 < inkCanvas.ActualHeight; y1 += cellSize)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Color.FromArgb(64, 0, 0, 255));
            line.IsHitTestVisible = false;
            line.X1 = 0d;
            line.X2 = inkCanvas.ActualWidth;
            line.Y1 = y1;
            line.Y2 = y1;
            cvsGrid.Children.Add(line);
        }
    }
    

    The basic idea is to have a Canvas in the back of the InkCanvas to actually hold the grid lines (so the lines aren't added to the InkCanvas and thus can't be selected).

    Hope this helps.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    • Marked as answer by usabilitytank Saturday, January 2, 2010 7:51 PM
    Tuesday, December 29, 2009 11:06 AM
    Moderator
  • Again, thanks for your replies, Jie!  I used a similar concept because my InkCanvas has a background image and if the Canvas was in back, as you suggested, it would be obscured by the background image...I believe.  So I created a grid Canvas to be a child of the InkCanvas parent.  The grid appears exactly as I want it. 

    But now, when I draw a selection around the top/left corner, adornment boxes show up in the top/left corner around the grid Canvas which is 0,0 h/w (I know it's the Canvas that's selected because when I press delete the grid lines go away).  I need to make the grid Canvas read only for the user.  I tried this:

    gridCanvas.IsHitTestVisible = false; 

    ...but that didn't work.  Do you know how to make the child Canvas read-only or *not* selectable?

    Thanks

    Saturday, January 2, 2010 8:09 PM
  • Hi,

    Could you try still put the Canvas as the container of the InkCanvas, and move the background image from the InkCanvas to Canvas, and keep the Background of InkCanvas transparent? I think that can produce the effect you want.

    Any problems please let me know.

    Regards,
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The CodeFx Project
    My Blog (in Simplified Chinese)
    Monday, January 4, 2010 6:08 AM
    Moderator