简体   繁体   English

如何在Win Store App(8.1)中扩展Windows.UI.Xaml.Shapes.Shape?

[英]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类的问题,我找到了两个解决方案:

  1. extend your class by the Path class 通过Path类扩展您的类
  2. create your custom control based on an ordinary class 创建基于普通类的自定义控件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows应用商店应用中使用MIDI(Win 8.1) - Working with MIDI in Windows Store App (Win 8.1) 如何将Windows商店中的Windows手机应用程序(8.1 XAML)迁移到8.1 Silverlight? - How to Migrate a windows phone app(8.1 XAML) which is live in windows store to 8.1 Silverlight? 如何在Windows Phone 8.1 Xaml应用程序中找到内存泄漏的原因? - How to found a cause of memory leak at Windows Phone 8.1 Xaml app? 如何在Windows 8.1应用程序中对XAML网格视图进行排序? - How can I sort a XAML gridview in a Windows 8.1 app? 如何在Windows Store App中通过Web API(在线服务)和xaml UI绑定JSON数据? - How to Bind JSON data through Web API(Online Services) with xaml UI In Windows Store App? 单元测试Windows 8 Store App UI(Xaml控件) - Unit Testing Windows 8 Store App UI (Xaml Controls) Windows应用商店-XAML UI元素在C#代码中不可见 - Windows Store App - XAML UI element not visible in C# code 如何在C#/ XAML Windows应用商店(Metro UI)应用程序中混合使用浅色和深色主题? - How do I mix Light and Dark themes in a C#/XAML Windows Store (Metro UI) App? 在Windows 8.1运行时应用程序中动态加载Xaml - load Xaml dynamically in Windows 8.1 runtime app 使用XAML C#在Windows Store App 8.1中添加动态文本框 - Adding dynamic text boxes in windows store app 8.1 using xaml c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM