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

Diagram Save/Load Binding Bug :(

1 Answer 44 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
SPARE GmbH
Top achievements
Rank 2
SPARE GmbH asked on 06 Jul 2012, 03:39 PM
Hy,

I've got the following Problem.
If i Save the Diagram to String and Load the string back into the same Diagram, my binding doesn't work anymore.
Bug inside the Diagram Framework or OSI Layer 9 (20 cm in the front of the monitor) ?


XAML:
<telerik:RadDiagramShape x:Class="SPARE_BPMS_Framework.Shapes.General.ProcessShape"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" Content="{Binding}"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             d:DesignHeight="300" d:DesignWidth="300">
 
    <telerik:RadDiagramShape.Resources>
        <DataTemplate x:Key="editTemplate">
            <StackPanel Orientation="Horizontal">
                <TextBox Height="24" Text="{Binding Name}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="template">
            <WrapPanel Orientation="Vertical">
                <TextBlock Text="{Binding Name}" />
                <TextBlock Text="{Binding ChildProcessName}" />
            </WrapPanel>
 
        </DataTemplate>
    </telerik:RadDiagramShape.Resources>
</telerik:RadDiagramShape>

Code Behinde
public partial class ProcessShape : RadDiagramShape
    {
        public ProcessItem Model { get; set; }
 
        public string Name { get; set; }
 
        public ProcessShape()
        {
            InitializeComponent();
 
            Model = new ProcessItem();
           
            this.EditTemplate = (DataTemplate)this.FindResource("editTemplate");
            this.ContentTemplate = (DataTemplate)this.FindResource("template");
 
            this.DataContext = Model;
 
            this.MouseDoubleClick += new MouseButtonEventHandler(Model.shape_MouseDoubleClick);
        }
 
        public void Update()
        {
            this.EditTemplate = (DataTemplate)this.FindResource("editTemplate");
            this.ContentTemplate = (DataTemplate)this.FindResource("template");
 
        }
 
         
    }

Method who call the Reload and Load
string temp = diagram.Save();
                diagram.Clear();
            diagram.Load(temp);

Greetings

Alfred

1 Answer, 1 is accepted

Sort by
0
Accepted
Miro Miroslavov
Telerik team
answered on 10 Jul 2012, 08:00 AM
Hello Alfred,

 This is already answered in support thread, but I'll summarize the idea so that other guys can benefit of it.
Every time a diagram is deserialized (loaded), all the shapes are newly created, so all Binding related properties (DataContext, Templates)  should be manually set, since they are not saved by the diagram. (Here is the list of saved properties).
So here is the example code that should set the appropriate properties.

(e.Shape as RadDiagramShape).Content = new DataItem();
(e.Shape as RadDiagramShape).ContentTemplate = this.grid.FindResource("template") as DataTemplate;
(e.Shape as RadDiagramShape).EditTemplate = this.grid.FindResource("editTemplate") as DataTemplate;

Greetings,
Miro Miroslavov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Diagram
Asked by
SPARE GmbH
Top achievements
Rank 2
Answers by
Miro Miroslavov
Telerik team
Share this question
or