Diagram Save/Load Binding Bug :(

2 posts, 1 answers
  1. SPARE GmbH
    SPARE GmbH avatar
    18 posts
    Member since:
    Mar 2012

    Posted 06 Jul 2012 Link to this post

    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

  2. Answer
    Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 10 Jul 2012 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top