【问题标题】:How to get just the resulting strokes when erasing by point on InkCanvas?在 InkCanvas 上逐点擦除时如何获得结果笔画?
【发布时间】:2014-08-18 13:46:15
【问题描述】:

我不明白。假设我在 InkCanvas 上画了一个“S”。

OnStrokeCollected 事件将触发。在 OnStrokeCollected 事件中,我将笔画发送到 InkAnalyzer:

analyzer.AddStroke(e.Stroke)

现在我逐点擦除“S”的中心点。

OnStrokeErasing 事件触发。现在我可以从 InkAnalzyer 中删除原来的“S”了:

analyzer.RemoveStroke(e.Stroke)

但是,我现在有两招。原始“S”的顶部和底部。由于我现在有两个笔画,如何在不删除整个先前笔画集合并重新添加新笔画集合的情况下将这些“新”笔画中的每一个添加回 InkAnalyzer(已删除原始复合笔画“S”)?

我真诚地感谢任何想法。

【问题讨论】:

    标签: wpf inkcanvas ink-analyzer


    【解决方案1】:

    我能想到的唯一想法发布在下面。我肯定会感谢更好的解决方案。

    XAML

      <ink:CustomInkCanvas x:Name="inkcanvas"  Strokes="{Binding Strokes}" /> 
    

    视图模型

            strokes = new StrokeCollection();
            (strokes as INotifyCollectionChanged).CollectionChanged += (sender, e) =>
            {
                if (isErasingByPoint == true)
                {
                    if (e.OldItems != null && e.OldItems.Count > 0)
                    {
                        foreach (Stroke s in e.OldItems)
                        {
                        }
                    }
    
                    if (e.NewItems != null && e.NewItems.Count > 0)
                    {
                        foreach (Stroke s in e.NewItems)
                        {
                        }
    
                    }
                }
                isErasingByPoint = false;
    
            };
    
    
        public void OnStrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
        {
            // OnStrokeCollected event occurs AFTER StrokeCollection.CollectionChanged event.
            analyzer.AddStroke(e.Stroke);
        }
    
        public void OnStrokeErasing(object sender,  InkCanvasStrokeErasingEventArgs e)
        {
            // When erasingbypoint, OnStrokeErasing event occurs BEFORE StrokeCollection.CollectionChanged event.
            // if erasing by stroke, the StrokeCollection.CollectionChanged event is not called.
            if (EditingMode == InkCanvasEditingMode.EraseByPoint)
                isErasingByPoint = true;
            else
                analyzer.RemoveStroke(e.Stroke);
        }
    

    希望这对某人有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      相关资源
      最近更新 更多