I want to create an custom InkCanvas Adorner and found the logic behind:
You can re-use the existing lasso functionality of the InkCanvasEditingMode.Select mode. Then, in the SelectionChanged event, you can get a reference to the selected strokes (and/or elements). Now clear the selection (to get rid of the standard adorner) and then bring up your custom adorner.
How can i inherit the InkCanvas class with the editing mode in my own class and get access to the Events?
class myInkCanvasClass : InkCanvas ?
{
base class constructor call ?
...
}
You shouldn't have to inherit from InkCanvas
, SelectionChanged
is a public event on InkCanvas
so you can just add a handler to it. Also the EditingMode
is a public property that you can set on an instance of InkCanvas
as well. So to add the handler to SelectionChanged
and toggle the EditingMode
between Ink
and Select
you can just use the public API of an InkCanvas
instance.
Basic example:
inkCanvas.SelectionChanged += InkCanvas_SelectionChanged;
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
I managed to inherit the InkCanvas Class to my CustomInkCanvas Class and get the EventListener of SelectionChanged:
public class CustomInkCanvas : InkCanvas
{
//variables
//constructor
public CustomInkCanvas()
{
//...
}
override protected void OnSelectionChanged(EventArgs e)
{
MessageBox.Show("Selection Changed");
}
}
So if i change a Selection i get noticed.
[DebuggerDisplay("[{Scene}]Strokes:{Strokes.Count}, Children:{Children.Count}")]
public class InkCanvas_Sandeep : InkCanvas
{
public int PagId = -1;
public InkCanvas_Sandeep()
{
DefaultDrawingAttributes.Color = Colors.Red;
DefaultDrawingAttributes.FitToCurve = true;
DefaultDrawingAttributes.Height = 2;
DefaultDrawingAttributes.Width = 2;
DefaultDrawingAttributes.IgnorePressure = false;
DefaultDrawingAttributes.IsHighlighter = false;
DefaultDrawingAttributes.StylusTip = System.Windows.Ink.StylusTip.Ellipse;
DefaultDrawingAttributes.StylusTipTransform = Matrix.Identity;
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
SnapsToDevicePixels = true;
}
}
public void createMultipleInstances()
{
InkCanvas_Sandeep canvas new InkCanvas_Sandeep();
canvas.PagId = ++PageDetails.PageId;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.