[英]How to extend Windows.UI.Xaml.Shapes.Shape in Win Store App (8.1)?
After several hours of research on how to extend the Windows.UI.Xaml.Shapes.Shape
class, I need to ask you guys if anybody can help me. 在对如何扩展
Windows.UI.Xaml.Shapes.Shape
类进行了数小时的研究之后,我需要问你们是否有人可以帮助我。
Basically I need an ordinary rectangle (since its sealed, I cannot extend the Windows.UI.Xaml.Shapes.Rectangle
class) and add some members to it. 基本上,我需要一个普通的矩形(因为它是密封的,所以无法扩展
Windows.UI.Xaml.Shapes.Rectangle
类)并向其中添加一些成员。 So I need a class which draws a ordinary rectangle with additional members. 因此,我需要一个用其他成员绘制一个普通矩形的类。
Have you tried Extension Methods ? 您是否尝试过扩展方法 ?
public static class MyExtensions
{
public static Size GetSize(this Windows.UI.Xaml.Shapes.Rectangle rectangle)
{
return rectangle.RenderSize;
}
}
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Rectangle rectangle = new Rectangle();
Debug.WriteLine(rectangle.GetSize());
}
}
The Windows Runtime C# projection has a bunch of extensions, eg, AsInputStream . Windows运行时C#投影具有大量扩展,例如AsInputStream 。
For a great example of using extensions with Windows Runtime APIs see this article in the MSDN Magazine . 有关将扩展与Windows运行时API一起使用的好例子,请参阅《 MSDN杂志》中的这篇文章 。
The actual answer to the question would be to really extend a class by the Shape
class ( Windows.UI.Xaml.Shapes.Shape
). 该问题的实际答案是通过
Shape
类( Windows.UI.Xaml.Shapes.Shape
)真正扩展一个类。
Nevertheless I found two solutions for my problem where it isnt necessary to use the Shape
class: 不过,对于不需要使用
Shape
类的问题,我找到了两个解决方案:
Path
class Path
类扩展您的类
Path
isnt sealed this is possible (see how to draw a custom graphic with this example http://code.msdn.microsoft.com/windowsapps/Drawing-bfc39296/ ) Path
密封,因此这是可能的(请参见如何通过此示例http://code.msdn.microsoft.com/windowsapps/Drawing-bfc39296/绘制自定义图形)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.