WPF InkCanvas继承了类

时间:2016-05-16 19:11:34

标签: c# wpf inkcanvas

我想创建一个自定义的InkCanvas Adorner,并找到了背后的逻辑:

  

您可以重复使用 InkCanvasEditingMode.Select 模式的现有套索功能。然后,在SelectionChanged事件中,您可以获得对所选笔划(和/或元素)的引用。现在清除选择(摆脱标准装饰)然后调出自定义装饰。

如何在我自己的类中使用编辑模式继承InkCanvas类并访问事件?

class myInkCanvasClass : InkCanvas ?
{
    base class constructor call ?
    ...

}

3 个答案:

答案 0 :(得分:0)

您不必从InkCanvas继承,SelectionChangedInkCanvas上的公共事件,因此您只需为其添加处理程序即可。此外,EditingMode是一个公共属性,您也可以在InkCanvas的实例上设置。因此,要将处理程序添加到SelectionChanged并在EditingModeInk之间切换Select,您只需使用InkCanvas实例的公共API。

基本示例:

inkCanvas.SelectionChanged += InkCanvas_SelectionChanged;
inkCanvas.EditingMode = InkCanvasEditingMode.Select;

答案 1 :(得分:0)

我设法将InkCanvas类继承到我的CustomInkCanvas类并获取SelectionChanged的EventListener:

public class CustomInkCanvas : InkCanvas
{
    //variables 

    //constructor
    public CustomInkCanvas()
    {
       //...
    }

    override protected void OnSelectionChanged(EventArgs e) 
    {
        MessageBox.Show("Selection Changed");
    }
}

所以,如果我改变选择,我会注意到。

答案 2 :(得分:0)

[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;
}