This is a migrated thread and some comments may be shown as answers.

CustomShape in codebehind

3 Answers 109 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 13 Jul 2013, 06:57 PM
Hi!
I need to make a custom shape, but I need to draw it from the codebehind, because it needs to be drawn according to some properties. Also, the drawing will be composed of different geometries and brushes. Any chance I can use StreamGeometry with DrawingGroup somwhere ??
Do I need to override OnRender method of RadDiagramShape ??

Thanks very much for any help you could provide !!

David

3 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 17 Jul 2013, 12:43 PM
Hello David,
I think that you shouldn't have any problems using StreamGeometry and/or DrawingGroup (are you going to use the DrawingGroup with DrawingImage?). You'll just have to inherit our RadDiagramItem and add you custom methods that will set the geometry:
StreamGeometry geometry = new StreamGeometry();
geometry.FillRule = FillRule.EvenOdd;
 
// Open a StreamGeometryContext that can be used to describe this StreamGeometry 
using (StreamGeometryContext ctx = geometry.Open())
{
    ctx.BeginFigure(new Point(0, 80), true /* is filled */, true /* is closed */);
    ctx.LineTo(new Point(0, 0), true /* is stroked */, false /* is smooth join */);
    ctx.LineTo(new Point(80, 0), true /* is stroked */, false /* is smooth join */);
}
 
// Freeze the geometry (make it unmodifiable) for additional performance benefits.
geometry.Freeze();
 
this.Geometry = geometry;
I've attached a sample project showing this and if you need further assistance please feel free to ask us (if you send us a some code snippets and elaborate a little bit more on what exactly you want to do we'll be able to better help you).

Regards,
Zarko
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
David
Top achievements
Rank 1
answered on 17 Jul 2013, 01:26 PM
Thank you very much for the answer, Zarko!

Being able to use streamgeometry/geometrydrawing is a great starting point for us. But in the sample you joined to your post, we can affect only one geometry to the geometry property of the shape. What if I need a more complex shape composed of lot of geometries and brushes (see attached png) ?? This has to be drawn from code because it's drawn according to properties like nb of floors, etc...

Thans for your help!

David
0
Zarko
Telerik team
answered on 18 Jul 2013, 04:05 PM
Hi David,
Could you please take a look at my answer in this thread and if you have further questions feel free to ask.

Regards,
Zarko
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Diagram
Asked by
David
Top achievements
Rank 1
Answers by
Zarko
Telerik team
David
Top achievements
Rank 1
Share this question
or