locked
how to extend Windows.UI.Xaml.Shapes.Shape to create a custom shape? RRS feed

  • Question

  • Hey,

    after quite a lot research I decided to ask you about my problem. Basically I simply want to extend Windows.UI.Xaml.Shapes, I have done the same with System.Windows.Shapes.Shape but since I need to build a Win 8 Store App the Xaml.Shapes is needed? Any suggestions how to do this?

    The extended shape should look like a regular Rectangle but with a few extra attributes which I cant add to shapes.Rectangle because its a sealed class. This is part of a MS Visio like modeling tool where the rectangles can be tragged on a canvas.

    Thx in advance
    _akron_ 


    Thursday, December 19, 2013 2:22 PM

Answers

  • Right... I think Path should be able to do this, as it's not a sealed class.  You can create your shape and add the properties to it.

    You can also create a custom control which doesn't subclass Rectangle, but just uses it and allows you to set your own properties.  Custom User Control XAML Windows Store


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Proposed as answer by lois44 Thursday, January 9, 2014 3:58 PM
    • Marked as answer by _akron_ Thursday, January 9, 2014 4:05 PM
    Thursday, January 9, 2014 1:09 PM
    Moderator

All replies

  • You extend http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.shapes.shape.aspx instead of rectangle.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Anne Jing Monday, December 30, 2013 7:25 AM
    • Unmarked as answer by _akron_ Wednesday, January 8, 2014 1:48 PM
    Thursday, December 19, 2013 8:06 PM
    Moderator
  • You extend http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.shapes.shape.aspx instead of rectangle.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    I have the same problem. The question is how to draw such an extended class (e.g. MyShape : Shape)? The ordinary extension isnt the problem. I want to show my custom shape on a panel or canvas. Do you have further infos on this?
    • Edited by lois44 Wednesday, January 8, 2014 11:16 AM
    Wednesday, January 8, 2014 11:14 AM
  • I never wanted to extend Rectangle, as I said in my first entry i have recogniced it as sealed sorry for confusion. The question is more about how to extend http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.shapes.shape.aspx so it will be drawn properly? What functions and properties to i need to implement so it gets drawn? All examples i have found so far combine just basic shapes in XAML and do not extend the Shape class.

    thx in advance

    _akron_

    Wednesday, January 8, 2014 1:33 PM
  • Does Path do what you need?

    EDIT: should have said Path


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.


    Wednesday, January 8, 2014 3:48 PM
    Moderator
  • Hey Matt,

    to give you an idea what I try to do you can have a look at this artikel: http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=65924 . MY solution should be a Win 8.1 app, the idea is basically the same. So its not so much about the visual style, a rectangle in the first moment is fine but i need to append properties such as connectors and settings and stuff which i cant by using one of the shape sub classes. 

    Maybe my approach is totally wrong, but thats the only idea I got so far. I came to this idea because of this artikel: http://msdn.microsoft.com/de-de/magazine/cc337899.aspx its in german. but if you scroll down to "Figure 6 CenteredEllipse.cs – Die CenteredEllipse-Klasse" you see the code which is speaking itself.

    thx in advance

    _akron_

    Wednesday, January 8, 2014 5:26 PM
  • Right... I think Path should be able to do this, as it's not a sealed class.  You can create your shape and add the properties to it.

    You can also create a custom control which doesn't subclass Rectangle, but just uses it and allows you to set your own properties.  Custom User Control XAML Windows Store


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Proposed as answer by lois44 Thursday, January 9, 2014 3:58 PM
    • Marked as answer by _akron_ Thursday, January 9, 2014 4:05 PM
    Thursday, January 9, 2014 1:09 PM
    Moderator
  • I did it with a custom control as can be seen in http://code.msdn.microsoft.com/windowsapps/XAML-user-and-custom-a8a9505e.
    Thursday, January 9, 2014 3:58 PM