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

Programmatically build up RadDock from app.config file

1 Answer 88 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 01 Aug 2011, 05:28 PM
I am looking into replacing our current docking control with the RadDock control. What our current dock control allows us to do is have a fairly simple xml configuration to allow dynamic layouts. We have a bunch of controls that can be dynamically loaded, the customer can control which controls are loaded and the layout (dock position, auto hide, and so on).

Example plugin config
<plugin load="true"
        type="AssemblyName, ClassName"
        path=".">
    <Form>
        <Guid>d3b14ad1-e970-4445-9a27-2cedf211ca3a</Guid>
        <AllowedDock>All</AllowedDock>
        <CurrentDock>Bottom</CurrentDock>
        <CurrentMode>Inner</CurrentMode>
        <IsSelected>true</IsSelected>
        <IsAutoHide>false</IsAutoHide>
        <Width>400</Width>
        <Height>371</Height>
        <ParentGuid>1fbc51f7-f459-425b-884d-91a33602440c</ParentGuid>
        <Name>PTZ</Name>
        <Screen>1</Screen>
    </Form>
</plugin>

This control is a child (controlled by CurrentMode tag) and will be display in the bottom portion of it's parent (controlled by the CurrentDock tag). If the CurrentDock is changed to Fill then it will the same space as it's parent and become a TabControl.

My question is, does the RadDock have the ability to allow me to dynamically build up this layout from a simple configuration? I would like to just add the RadDock control to the form and have it built up from the config file, the customer would also need to be able to change the layout.

This is the code that will load all the controls in the app.config file where plugin load = true. This seems to give me the parent / child tab layout I am looking for, but it seems like it's not the "right" way to do it. For instance, if I want two controls docked Left within the RadDock but tabbed, would it be better to create a ToolWindow and add those two controls to that, or pass in the target control (parent) while calling DockControl?

foreach (SnapInBase plugin in BuildPluginHierarchy(this.plugins))
{
    try
    {
        if (plugin.MetaData.ContainsKey("Form") && plugin.MetaData["Form"] != null)
        {
            XmlNode n = plugin.MetaData["Form"];
 
            plugin.Dock = DockStyle.Fill;
 
            DockPosition position = ParseXmlNode<DockPosition>(n, "DockPosition");
            DockType dockType = ParseXmlNode<DockType>(n, "DockType");
 
            Guid guid = ParseXmlNode<Guid>(n, "Guid");
            int width = ParseXmlNode<Int32>(n, "Width", plugin.Width);
            int height = ParseXmlNode<Int32>(n, "Height", plugin.Height);
            bool isAutoHide = ParseXmlNode<Boolean>(n, "IsAutoHide");
            Guid parentGuid = ParseXmlNode<Guid>(n, "ParentGuid");
            int screen = ParseXmlNode<Int32>(n, "Screen", 1);
 
            if (screen == 1)
            {
                if (parentGuid != Guid.Empty)
                {
                    HostWindow parent;
                    if (this.controlCache.TryGetValue(parentGuid, out parent) == true)
                    {
                        HostWindow window = null;
 
                        window = this.radDock1.DockControl(plugin, parent, position, dockType);
 
                        if (isAutoHide == true)
                        {
                            this.radDock1.AutoHideWindow(window);
                        }
 
                        this.controlCache.Add(guid, window);
                    }
                }
                else
                {
                    var window = this.radDock1.DockControl(plugin, position, dockType);
 
                    if (isAutoHide == true)
                    {
                        this.radDock1.AutoHideWindow(window);
                    }
 
                    this.controlCache.Add(guid, window);
                }
            }
        }
        else
        {
            logger.Error(string.Format("No form metadata for {0}", plugin.Name));
        }
    }
    catch (Exception ex)
    {
        logger.Error(ex);
    }
}

What I am hoping for is to find out is if there is a better way to do what I'm trying to do. I will provide the customer a default layout, and they can change it how they see fit.

Thanks,
Matt

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 03 Aug 2011, 12:30 PM
Hi Matthew,

You can use RadDock Save/Load Layout feature to support this functionality. The RadDock control can save/load layout using file, Stream, TextWriter/TextReader. More information you can find in our online documentation.

I hope this information is useful. Let me know if you need further assistance.

Regards,
Julian Benkov
the Telerik team

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

Tags
Dock
Asked by
Matthew
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or