简体   繁体   中英

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.

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:

  1. extend your class by the Path class
  2. create your custom control based on an ordinary class

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM