c# - 是否有通用的 InkCanvas StrokesChanged 类型的事件?

标签 c# .net wpf events inkcanvas

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

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/

相关文章:

c# - app.config 的内置 .NET 键/值对 configSection 处理程序

c# - 如何使用 neo4jclient 展开两个列表?

c# - 如何使用自定义 DefaultBackColor 制作 UserControl?

.net - 为什么在 .Net 中是 "new EventHandler(Handler)"?

c# - 如何在 Page.Resources 中包含两个资源?

c# - 将 CollectionViewSource 绑定(bind)到 ListBox

c# - 如何在命名空间中路由混合 MvcApplication 和 WebApiApplication?

c# - 在 dnn 中构建模块需要文本编辑器放置的建议与消息不在同一行

.net - CloudConfigurationManager.GetSetting ("")实际上是如何工作的?

wpf - 如何设置 Avalon 对接管理器来像 VS 一样调整大小?