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.
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. 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 .
For a great example of using extensions with Windows Runtime APIs see this article in the MSDN Magazine .
The actual answer to the question would be to really extend a class by the Shape
class ( Windows.UI.Xaml.Shapes.Shape
).
Nevertheless I found two solutions for my problem where it isnt necessary to use the Shape
class:
Path
class
Path
isnt sealed this is possible (see how to draw a custom graphic with this example http://code.msdn.microsoft.com/windowsapps/Drawing-bfc39296/ )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.