CustomShape in codebehind

4 posts, 0 answers
  1. David
    David avatar
    4 posts
    Member since:
    Jul 2013

    Posted 13 Jul 2013 Link to this post

    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
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 17 Jul 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    4 posts
    Member since:
    Jul 2013

    Posted 17 Jul 2013 Link to this post

    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
  5. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 18 Jul 2013 Link to this post

    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 >>
Back to Top