为什么 System.Windows.Shape.Path 被密封?

发布于 2024-08-06 02:45:56 字数 111 浏览 7 评论 0原文

我试图扩展形状类以包含附加变量,但发现该类是密封的。我怎样才能使用替代实施方法简单地实现这一目标?

正在创建一个新类并存储一个形状,并通过最简单的方法传递所有方法调用;我确信还有更好的方法吗?

I was trying to extend the shape class to contain an additional variable but have found the class is sealed. How can I achive this simply, using an alternate implementation approach?

Is creating a new class and storing a shape an passing all the method calls through the easiest approach; I'm sure there is a better way though?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久夏青 2024-08-13 02:45:56

如果您要添加的变量是您只能读取的变量,并且是作为 Path 类其他成员的结果进行计算的,则可以添加一个将返回您的值的扩展方法。

但是,如果情况并非如此:

请考虑创建一个继承自 Path 的父类 - Shape 的类,该类未密封。
然后向其中添加一个私有 Path 成员。您可以免费获取所有形状方法调用,并且只需为 Path 的唯一成员提供包装器。

If the variable you want to add is one which you would only ever be reading from, and is calculated as a result of other members of the Path class, you could add an extension method which would return your value.

However, if this is not the case:

Consider creating a class which inherits from Path's parent - Shape, which is not sealed.
Then add a private Path member to this. You can grab all the shape method calls for free and would only have to provide wrappers for the unique members of Path.

听闻余生 2024-08-13 02:45:56

WPF 有一个强大的概念,名为附加属性。我不确定你想做什么,但也许你可以通过使用这个概念来解决你的问题。举个例子,Grid.RowGrid.Column 属性是附加到Grid 内元素的属性。

<Grid>
  ...
  <TextBlock Grid.Row="1" Grid.Column="2" ... />
</Grid>

TextBlock 类不知道 Grid 使用的 Grid.RowGrid.Column 属性。

您可以在MSDN 上阅读有关附加属性的更多信息。

WPF has a powerful concept named Attached Properties. I'm not sure what you are trying to do, but perhaps you can solve your problem by using this concept. To provide an exampe, the Grid.Row and Grid.Column properties are properties attached to elements inside a Grid.

<Grid>
  ...
  <TextBlock Grid.Row="1" Grid.Column="2" ... />
</Grid>

The TextBlock class is unaware of the Grid.Row and Grid.Column properties used by the Grid.

You can read more about attached properties on MSDN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文