积极答复者
InkCanvas中Stroke的操作问题

问题
-
版主,你好!
我曾经在
http://social.msdn.microsoft.com/Forums/zh-CN/wpfzhchs/thread/e8630a99-263b-4d79-9750-5106a3574c5f/
这个帖子中问过 关于在InkCanvas中使用Stroke的Draw()方法画图的问题,现在已经可以实现基本的画图
我现在想问的是,如何能实现和原本的InkCanvas效果相同的橡皮擦功能
比如,我把InkCanvas的inkCanvas.EditingMode 设置成 Ink 即可以在上面书写
然后把inkCanvas.EditingMode设置成InkCanvasEditingMode.EraseByPoint 就可以擦掉原来写的了
但是用了Draw()方法画出来的图,貌似用橡皮擦不能擦点,只能擦整个Stroke 是这样的么.
Hero
答案
-
默认的笔迹和自定义的Stroke是有选中状态的,不光是对象上还是界面显示上都有。在界面上,装饰层都会显示一个Resize的边框的,可以让你来进行改变大小,比如我的那个例子,在Select模式下,就是这样子的:
Stroke对象上,有一个IsSelected 属性 (internal),他就能标记是否当前Stroke被选中。不过由于是internal的,所以我们需要在自定义的Stroke中把这个值通过反射Public出来。
public class customStroke : Stroke { public customStroke(StylusPointCollection pts) : base(pts) { this.StylusPoints = pts; } public bool IsSelected { get { PropertyInfo property = typeof(Stroke).GetProperty("IsSelected", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.NonPublic); return (bool)property.GetValue(this, null); } }
截图:
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Jie BaoModerator 2011年7月5日 3:01
-
是的,因为橡皮擦只能对于Stroke来操作,他不能分离Stroke,所以要么你完整的删掉一个Stroke,要么不删。由于你设计了自定义的Stroke,那个完整的图形就是一个Stroke,所以只能完整的擦出整个Stroke了。
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Jie BaoModerator 2011年7月5日 3:01
全部回复
-
是的,因为橡皮擦只能对于Stroke来操作,他不能分离Stroke,所以要么你完整的删掉一个Stroke,要么不删。由于你设计了自定义的Stroke,那个完整的图形就是一个Stroke,所以只能完整的擦出整个Stroke了。
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Jie BaoModerator 2011年7月5日 3:01
-
默认的笔迹和自定义的Stroke是有选中状态的,不光是对象上还是界面显示上都有。在界面上,装饰层都会显示一个Resize的边框的,可以让你来进行改变大小,比如我的那个例子,在Select模式下,就是这样子的:
Stroke对象上,有一个IsSelected 属性 (internal),他就能标记是否当前Stroke被选中。不过由于是internal的,所以我们需要在自定义的Stroke中把这个值通过反射Public出来。
public class customStroke : Stroke { public customStroke(StylusPointCollection pts) : base(pts) { this.StylusPoints = pts; } public bool IsSelected { get { PropertyInfo property = typeof(Stroke).GetProperty("IsSelected", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.NonPublic); return (bool)property.GetValue(this, null); } }
截图:
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Jie BaoModerator 2011年7月5日 3:01