Answered by:
how to extend Windows.UI.Xaml.Shapes.Shape to create a custom shape?

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.Thursday, January 9, 2014 1:09 PMModerator
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.Thursday, December 19, 2013 8:06 PMModerator -
You extend http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.shapes.shape.aspx instead of rectangle.
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?
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.
- 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.
- Edited by Matt SmallMicrosoft employee, Moderator Wednesday, January 8, 2014 3:55 PM
Wednesday, January 8, 2014 3:48 PMModerator -
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.Thursday, January 9, 2014 1:09 PMModerator -
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