how to add dynamically ContentTemplete to RadDiagramShape ?

3 posts, 0 answers
  1. Sopan
    Sopan avatar
    34 posts
    Member since:
    May 2012

    Posted 19 Aug 2013 Link to this post

    HI,

    I want to add the RadDiagramShape dynamically to RadDiagram control but wants to change the ContentTemplete.
    <telerik:RadDiagram x:Name="myDiagram">
     
     </telerik:RadDiagram
    private void btnAddNewShape_Click(object sender, System.Windows.RoutedEventArgs e)
           {
               DataTemplate templete = new DataTemplate(typeof(RadRichTextBox));
     
               this.myDiagram.AddShape(new RadDiagramShape() { });
           }


    But the content editor not show RadRichTextBox, It show normal Content Property as String.


    So How to add dynamically ContentTemplete of RadDiagramShape


    Thanks

    Sopan Vaidya
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 21 Aug 2013 Link to this post

    Hi Sopan,
    You don't see a RadRichTextBox because you've set the DataType of your DataTemplate(DT) not its content. It's not a common practice go set DTs in code-behind but if you want to it is possible:
    1) you could get a DT resource and set it.
    2) you could create your own DT in code using the FrameworkElementFactory.
    I've attached a sample project showing both approaches so you could decide which one is better for you.
    Just one question - do you really need to set the ContentTemplatate ? Why don't you set the Content directly:
    newShape.Content = new RadRichTextBox();
    I hope I was able to help you and if you have more 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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sopan
    Sopan avatar
    34 posts
    Member since:
    May 2012

    Posted 21 Aug 2013 Link to this post

    Thank you Zarko  this demo too helped me.
Back to Top