如何继承画布的属性 [英] How to inherit attached propeties for inkcanvas

查看:127
本文介绍了如何继承画布的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个customInkCanvas,它继承自InkCanvas.

我有一张要放置在InkCanvas上的图像.

对于普通的InkCanvas,它可以起作用:

I have a customInkCanvas which inherits from InkCanvas.

I have an image that I wish to place on the InkCanvas.

For the normal InkCanvas, this works:

Canvas.SetTop(image, y);
Canvas.SetLeft(image, x);
InkCanvas.Children.Add(image);


但是,对于CustomInkCanvas,以上操作将失败.那么如何在CustomInkCanvas上放置元素?

我猜想Top,Left等是InkCanvas的附加属性,而不会传递给customInkCanvas.

任何帮助将不胜感激!

我已经意识到这实际上是一个两部分的问题:
1.我想念InkCanvas不能从Canvas继承,所以我需要用InkCanvas.SetTop()替换Canvas.SetTop().了解到这一点之后,有没有办法
2.继承还是传递附加的属性?

感谢


However, for CustomInkCanvas, the above fails. So how do I position an element on the CustomInkCanvas?

I''m guessing that Top,Left, etc, are attached properties to InkCanvas and are not passed down to customInkCanvas.

Any help will be really appreciated!

I''ve realized this is actually a two-part question:
1. I missed that InkCanvas does NOT inherit from Canvas, so I was needing to replace Canvas.SetTop() with InkCanvas.SetTop(). Having learned that, is there a way to
2. Inherit or pass-down attached properties?

Thanks

推荐答案

附加属性不会以继承类成员或方法的方式继承.
当我们谈论附加属性被继承时,我们通常指的是在可视树的父元素上设置的附加属性的值也适用于该节点的子级(除非被新值覆盖).

例如,以Grid.Row附加属性为例,您可以设置Label s和Checkbox es的依此类推,依此类推,但这并不意味着这些控件从某种程度上继承了Grid的附加属性. br/>
相反,Grid类的职责是在进行布局时检查是否设置了Grid.Row值(或使用默认值),并使用该值正确定位元素.

在您的示例中;
Attached properties are not inherited in the way members or methods of classes are inherited.
When we talk about attached properties being inherited we usually refer to the value of an attached property set on a parent element of the visual tree also applies to the children of that node (unless overridden with a new value).

Think of the Grid.Row attached property for example, you can set if for Labels and Checkboxes and so on, but that doesn''t mean that these controls somehow inherit the attached property from Grid.

Instead, it''s the responsibility of the Grid class to check if the Grid.Row value is set (or use the default value) when doing layout and use the that value to correctly position the element.

In your example;
InkCanvas.SetTop(image, y);
InkCanvas.SetLeft(image, x);
InkCanvas.Children.Add(image);



变量xy附加到image,然后InkCanvas查看通过MeasureOverrideArrangeOverride的过程中的变量.这意味着,如果您的CustomInkCanvas没有覆盖InkCanvas中的那些方法,那么将不会观察到这些值.

希望这会有所帮助,
弗雷德里克(Fredrik)



The variables x and y are attached to image, and then InkCanvas looks at those during it''s MeasureOverride and ArrangeOverride passes. This means that if your CustomInkCanvas not overrides those methods from InkCanvas then the values are not observed.

Hope this helps,
Fredrik


这篇关于如何继承画布的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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