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

Creating new RadDiagram dynamically

1 Answer 156 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Jakub asked on 22 May 2015, 09:02 AM

Hallo,

 

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

 

Grettings 

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>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 25 May 2015, 08:02 AM
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)



Regards,
Petar Mladenov
Telerik
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
Tags
Diagram
Asked by
Jakub
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or