Save/Load layout with Catel MVVM framework

6 posts, 0 answers
  1. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 14 Jul 2015 Link to this post

    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

  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 16 Jul 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 05 Aug 2015 Link to this post

    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 

  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 06 Aug 2015 Link to this post

    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
  6. Paolo
    Paolo avatar
    423 posts
    Member since:
    Jun 2009

    Posted 06 Aug 2015 Link to this post

    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?

  7. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 07 Aug 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready