Creating new RadDiagram dynamically

2 posts, 1 answers
  1. Jakub
    Jakub avatar
    26 posts
    Member since:
    Apr 2015

    Posted 22 May 2015 Link to this post



    I'd like to ask about my problem. I have app where i'm working with tabControl and RadDiagram. First RadDiagram is created in  xaml code and it's loaded manualy with some logic from the xml file. DragDrop logic is based on your DragDrop tutorial and it's working fine. But when i try create diagram manualy behind the code with my own method which is defining the most important things in diagram i don't know how to make it works with my DragDropBehavior Class.

    How could i define dragDrop:DragDropBehaviorRadDiagram.IsEnabled="True" behind code when i'm create new diagram?


    thank you for your time and advices



    Jakub Rautner

    private RadDiagram CreateNewDiagram()
               RadDiagram dgrm = new RadDiagram();
              // Events handlers
               dgrm.ShapeDoubleClicked += new EventHandler<ShapeRoutedEventArgs>(diagram_ShapeDoubleClicked);
               dgrm.MouseDoubleClick += new MouseButtonEventHandler(diagram_MouseDoubleClick);
               dgrm.SelectionChanged += new SelectionChangedEventHandler(diagram_SelectionChanged);
               dgrm.ZoomChanged += new EventHandler<RadRoutedPropertyChangedEventArgs<double>>(diagram_ZoomChanged);
               DragDropManager.AddDropHandler(dgrm, OnDrop);
               dgrm.Style = this.Resources["diagramStyle"] as Style;
               dgrm.ShapeStyleSelector = xGrid.Resources["CustomShapeStyleSelector"] as NodeStyleSelector;
               dgrm.ConnectionStyleSelector = xGrid.Resources["CustomConnectionStyleSelector"] as LinkStyleSelector;
               dgrm.LayoutAsync(LayoutType.Tree, TreeSettings);
               dgrm.IsDraggingEnabled = true;
               dgrm.AllowDrop = true;
               return dgrm;


    Here' s definition RadDiagram in xaml file:  dragDrop is namespace where i have created DragDropBehavior logic for TreeView and RadDiagram 

    <telerik:RadDiagram x:Name="diagram" Grid.Row="0"
      ShapeStyleSelector="{StaticResource CustomShapeStyleSelector}"
      ConnectionStyleSelector="{StaticResource CustomConnectionStyleSelector}"
      Style="{StaticResource diagramStyle}"
      ZoomChanged="diagram_ZoomChanged"                                                    IsZoomEnabled="True"                                                      MouseDoubleClick="diagram_MouseDoubleClick"                                                    AllowDrop="True"                                                    dragDrop:DragDropBehaviorRadDiagram.IsEnabled="True"                                                    ShapeDoubleClicked="diagram_ShapeDoubleClicked"                                                    SelectionChanged="diagram_SelectionChanged">                                    <primitives:ItemInformationAdorner.AdditionalContent>                                        <telerik:SettingsPane x:Name="xSettingsPane" Diagram="{Binding ElementName=diagram}">                                        </telerik:SettingsPane>                                    </primitives:ItemInformationAdorner.AdditionalContent>                                </telerik:RadDiagram>


  2. Answer
    Petar Mladenov
    Petar Mladenov avatar
    2882 posts

    Posted 25 May 2015 Link to this post

    Hi Jakub,

    If I understand correctly, the question is general - how to set attached property in code behind.
    The pattern is simple - Canvas.Top="100" set on some grid with x:Name="grid"  in XAML looks like:
    Canvas.SetTop(this.grid, 100)
    in code behind.

    In your scenario the code should be much like:
    DragDropBehaviorRadDiagram.SetIsEnabled(dgrm, true)

    Petar Mladenov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top