本质上,我想做的是为画布触发一种“脏”状态,以便我知道是否有未保存的更改。

WPF InkCanvas中是否有事件可以在笔触更改时随时处理?

如果没有,我应该听哪些事件进行等效操作?我的第一个猜测是:

StrokeCollected
StrokeErased
StrokesReplaced


尽管我可能是错的,并且缺少了一个案例。

注意:如果我得到假阳性(实际上没有标记为脏)不是什么大问题,但是我不想要假阴性。

最佳答案

这些事件似乎可以完成任务:


InkCanvas.StrokesReplaced(在设置Strokes属性时发生)
StrokeCollection.StrokesChanged(在添加或删除笔划时发生)
Stroke.StylusPointsChanged(在更改笔触形状时发生)
Stroke.StylusPointsReplaced(在设置StylusPoints属性时发生)
Stroke.DrawingAttributesChanged(在更改笔触的属性时发生)
Stroke.DrawingAttributesReplaced(在设置DrawingAttributes属性时发生)


就我而言,我从不替换属性或更改图形属性,因此仅使用StrokeCollection.StrokesChangedStroke.StylusPointsChanged。这是我的代码片段。

public MainWindow()
{
    inkCanvas.Strokes.StrokesChanged += Strokes_StrokesChanged;
}

private void Strokes_StrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
{
    // Mark dirty
    foreach (Stroke stroke in e.Added)
    {
        stroke.StylusPointsChanged += stroke_StylusPointsChanged;
    }
    foreach (Stroke stroke in e.Removed)
    {
        stroke.StylusPointsChanged -= stroke_StylusPointsChanged;
    }
}

private void stroke_StylusPointsChanged(object sender, System.EventArgs e)
{
    // Mark dirty
}

关于c# - 是否有通用的InkCanvas StrokesChanged事件类型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13353637/

10-12 12:54
查看更多