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

Save/Load layout with Catel MVVM framework

5 Answers 158 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 14 Jul 2015, 01:29 PM

Hello,

I'm trying to perform the save/load layout of Raddocking with CatelMVVM but I've some points to spot out.

I've implemented the two commands as found on example

 

private void OnSaveLayoutCommandCommandExecuted(object parameter)
    {
        this.dockingLayout = this.SaveLayoutAsString(parameter as RadDocking);
 
        // Replace the path from the Layout.xml with the one from the current OS
        File.WriteAllText(@"c:\temp\Layout.xml", this.dockingLayout);
    }
 
    private void OnLoadLayoutSourceCommandExecuted(object parameter)
    {
        // Replace the path from the Layout.xml with the one from the current OS
        this.dockingLayout = File.ReadAllText(@"c:\temp\Layout.xml");
 
        if (!string.IsNullOrEmpty(this.dockingLayout))
        {
            this.LoadLayoutFromString(parameter as RadDocking);
        }
    }
 
    private string SaveLayoutAsString(RadDocking docking)
    {
        MemoryStream stream = new MemoryStream();
        docking.SaveLayout(stream);
        stream.Seek(0, SeekOrigin.Begin);
        StreamReader reader = new StreamReader(stream);
 
        return reader.ReadToEnd();
    }
 
    private void LoadLayoutFromString(RadDocking docking)
    {
        using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(dockingLayout)))
        {
            stream.Seek(0, SeekOrigin.Begin);
            docking.LoadLayout(stream);
        }
    }

But when I load the layout I got the Pane position correctly fileld but the content is empty (and I understand this since it doesn't know what it has to store in.

Anyone has faced a similar problem and has found a solution? I tought of adding a tag that identifies the type but what about optional parameters? should I add them as well in the serialization tag?

Thanks

5 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 16 Jul 2015, 11:03 AM
Hello Paolo,

Thank you for contacting us.

By design in the RadDocking control the Save/Load layout functionality does not save and load the content of the RadPane instances in the control but rather saves/loads only the layout of those instance. You can take a look at this help article in our online documentation that described in details how the content of a RadPane could be restored when the LoadLayout functionality is used.

Regards,
Vladi
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
0
Michele
Top achievements
Rank 2
answered on 05 Aug 2015, 03:10 PM

Hello Vladi ,

In my case I've not got only simple properties but using a MVVM pattern I should reload the viewmodel (I don't want to restore the filters and data loaded just the default view/viewmodel)

 

Have u got any example using an MVVM pattern (I don't ask it to be catel, but maybe unity/caliburn micro)

 Thanks 

0
Vladi
Telerik team
answered on 06 Aug 2015, 07:03 AM
Hello Paolo,

You can take a look at our XAML SDK repository located at GitHub for all of the currently available SDK example projects. One of the available examples named "VisualStudioDocking" showcases how the RadDocking control could be used in MVVM scenarios in recreating the functionality of the MS Visual Studio IDE docking manager. That example includes the save/load layout functionality.

Hope this is helpful.

Regards,
Vladi
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
0
Michele
Top achievements
Rank 2
answered on 06 Aug 2015, 01:20 PM

Hello Vladi,

Thanks for your example...it's really appreciated...by the way in your case you serialize a PaneViewModel, I've a Viewmodels that inherits from 

public class DockViewModelBase : ViewModelBase, IDockViewModelBase, IMenuItem, IMenuWeakListener, IPersistence

is the PaneViewModel just a wrapper around my viewmodel?

0
Vladi
Telerik team
answered on 07 Aug 2015, 07:25 AM
Hi Paolo,

The PaneViewModel is an object that represents a "RadPane" instance when the PanesSource of the control is in use. By design the PanesSource could be set to a collection of any type of objects including directly setting it to a collection of RadPane instances. In the case when it is set directly to a collection of RadPane objects those exact instances will be used and will be added to the RadDocking control. In all other cases where the PanesSource is set to a collection of other types objects those objects will be used by the control's DockingPanesFactory in order to correctly transform them to a valid RadPane instances. In this case it is best to refer to those object as "ViewModels" as they contain the data that will be used inside the RadPane's Content and for the properties of the RadPane (Header etc.).

I hope this answers your question.

Regards,
Vladi
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
Docking
Asked by
Michele
Top achievements
Rank 2
Answers by
Vladi
Telerik team
Michele
Top achievements
Rank 2
Share this question
or