从InkCanvas中删除单个笔划 [英] Delete a single stroke from an InkCanvas

查看:68
本文介绍了从InkCanvas中删除单个笔划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Windows Dev社区!我正在制作一个使用InkCanvas的应用程序,并且迄今为止在克服障碍方面取得了成功。唉,我的成功已经结束,需要一些帮助。基本上我需要能够以编程方式从Ink Canvas中删除单个笔划
,并且我能够找到能够做类似事情的唯一删除函数是StrokeContainer.DeleteSelected方法,但它不完全是什么我需要。任何提示或建议都将不胜感激。


Hello Windows Dev community! I am in the process of making an app that utilizes the InkCanvas, and have had success so far in overcoming roadblocks. Alas, my success has ended and need some help. Essentially I need the ability to remove a single stroke from the Ink Canvas programmatically, and the only delete function I have been able to find capable of doing something similar is the StrokeContainer.DeleteSelected method, but it isn't exactly what I need. Any tips or suggestions would be greatly appreciated.

推荐答案

你好windevnoob,

Hello windevnoob,

欢迎来到开发通用Windows应用论坛! 

请阅读粘贴帖子,特别是  指南发布:主题行标签 &absp; 已知的
Windows 10 SDK和工具的问题 

Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools .

首先,请帮助我们编辑您的代码,以便我们了解您的项目类型。

First of all please help us edit your tags so that we can know your project type.

然后请看这个类:
InkStrokeContainer类
该类是我们用于处理stokes的类,它也是您找到DeleteSelected方法的地方。我们可以看到唯一与删除相关的方法是

DeleteSelected
类。让我们回到你的问题:

Then please see this class: InkStrokeContainer class The class is the class we used for handle stokes and it is also where you find the DeleteSelected method. We can see that the only delete related method is this DeleteSelected class. So let's go back to your question:

>>基本上我需要能够以编程方式从Ink Canvas中删除一个笔划,

>>Essentially I need the ability to remove a single stroke from the Ink Canvas programmatically,

解决方案1:

Solution1:

实际上要在UWP中执行此操作,我们已经使用了默认的InkToolbar,请看这里:

Actually to do this in UWP we have the Default InkToolbar which already did this, please see here:

添加一个InkToolbar

你可以使用默认的擦除按钮来完成这项工作。

Where you can use the default erasebutton to finish this job.

解决方案2:

Solution2:

抱歉,我在这里犯了错误,我将更新解决方案。在这种情况下,请检查
Rob的回复

Sorry I've made a mistake here and I will update the solution. Please check Rob's reply on this case:

https://social.msdn.microsoft.com/Forums/en-US / 352f44b0-4545-4411-92cb-dea72acfd093 / deletion-strokes-from-inkmanager?forum = winappswithcsharp

他已经指出我们可以做如下的事情:

He has already pointed out we can do something like the following:

" 您可以使用InkManager.GetStrokes获取笔画集合,然后以这种方式操纵笔画。虽然您仍然只能删除所选的笔画,但您可以遍历该集合以选择要删除的笔画 。"

"You can get the strokes collection with InkManager.GetStrokes and then manipulate the strokes that way. While you can still only delete the selected strokes, you can loop through the collection to select the ones that you want to delete."

在代码中将看起来如下,我已经做了测试:

In code which will looks like the following, for which I've already did a test:

 private void erase_mode_click(object sender, RoutedEventArgs e)
        {

            myInkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected;
        }

        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var StrokeCollection=myInkCanvas.InkPresenter.StrokeContainer.GetStrokes();
            teststroke = StrokeCollection[0];
            teststroke.Selected = true;
        }

        private void myInkCanvas_Tapped(object sender, TappedRoutedEventArgs e)
        {

            e.GetPosition(myInkCanvas);
            
        }

        private void deletebutton_Click(object sender, RoutedEventArgs e)
        {
            myInkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
        }

逻辑如下:

1。我们有一个StrokeContainer,它可以使用GetStokes来获取IReadOnlyList< InkStroke>收集我们的InkStrokes。

1. We have a StrokeContainer which can use GetStokes to get the IReadOnlyList<InkStroke> collection of our InkStrokes.

2。然后我们可以通过索引遍历集合以获取特定的InkStroke。

2. Then we can loop through the collection via index to get the specific InkStroke.

3。我们可以将InkStroke设置为代码

3. We can set the InkStroke as selected in code

4中的选择。然后我们可以使用StrokeContainer.DeleteSelected删除选定的InkStroke。这样,虽然我们正在尝试使用StrokeContainer.DeleteSelected。我们仍然可以删除特定的InkStroke。

4. Then we can use StrokeContainer.DeleteSelected to delete selected InkStroke. In this way although we are trying to use StrokeContainer.DeleteSelected. We can still delete a specific InkStroke.

祝你好运,

Barry


这篇关于从InkCanvas中删除单个笔划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆