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

Document window save state.

3 Answers 98 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Hugues
Top achievements
Rank 1
Hugues asked on 29 Jan 2015, 12:09 AM
I have notice that when i hide a document window and show it, it is showing back up in the main tab window. How can i get it to show up exactly where i had it close. The issue is that i have 4 document windows and i want my documents window to show back up exactly where they were before i hide them. I do notice that this seems to work with Tool windows, but i would like to know if it is possible with document windows.

Thanks,
Jerome.

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 02 Feb 2015, 02:53 PM
Hi Jerome,

Thank you for writing.

You could reach this type of behavior by subscribing to a number of events and manually updating the location of the hidden floating windows. I have prepared a sample implementation below:
public partial class Form1 : Form
{
    private Dictionary<string, Point> hiddenWindowsData = new Dictionary<string, Point>();
 
    public Form1()
    {
        InitializeComponent();
 
        this.Load += Form1_Load;
        this.radDock1.DockStateChanged += radDock1_DockStateChanged;
        this.radDock1.DockStateChanging += radDock1_DockStateChanging;
        this.radDock1.FloatingWindowCreated += radDock1_FloatingWindowCreated;
    }
 
    private void radDock1_DockStateChanged(object sender, DockWindowEventArgs e)
    {
        if (e.DockWindow.DockState == DockState.Floating)
        {
            e.DockWindow.FloatingParent.Tag = e.DockWindow.Text;
        }
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (DockWindow tW in this.radDock1.DockWindows.GetWindows(DockState.TabbedDocument))
        {
            tW.CloseAction = DockWindowCloseAction.Hide;
        }
    }
     
    private void radDock1_DockStateChanging(object sender, DockStateChangingEventArgs e)
    {
        if (e.NewDockState == DockState.Hidden)
        {
            hiddenWindowsData[e.NewWindow.Name] = e.NewWindow.FloatingParent.Location;
        }
    }
 
    private void radDock1_FloatingWindowCreated(object sender, FloatingWindowEventArgs e)
    {
        e.Window.Shown -= Window_Shown;
        e.Window.Shown += Window_Shown;
    }
 
    private void Window_Shown(object sender, EventArgs e)
    {
        FloatingWindow fW = sender as FloatingWindow;
        if (fW != null)
        {
            if (fW.Tag != null)
            {
                fW.Text = fW.Tag.ToString();
            }
            if (hiddenWindowsData.ContainsKey(fW.Text))
            {
                fW.Location = hiddenWindowsData[fW.Text];
            }
 
        }
    }
 
    private void radButton1_Click(object sender, EventArgs e)
    {
        DockWindow[] hiddenWindows = this.radDock1.DockWindows.GetWindows(DockState.Hidden);
        foreach (DockWindow window in hiddenWindows)
        {
            window.Show();
        }
    }
}

I am also sending you a gif file showing how the elements look on my side.

I hope this information is helpful. Should you have further questions please do no hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Hugues
Top achievements
Rank 1
answered on 02 Feb 2015, 04:18 PM
This seems to work only if the windows if floating. How about if the document window is already docked to something and i hide it. Would it remember the position and also where it was previously dock to. I want the document window to be at the exact state it was before i close it. So if it was docked, it should remain dock if i open it again.

Thanks.
0
Hristo
Telerik team
answered on 05 Feb 2015, 02:17 PM
Hi Hugues,

Thank you for writing back.

Currently the RadDock control does not provide a functionality for saving the position of hidden document windows. When a docked document window gets hidden its container element the DocumentTabStrip becomes disposed and when the window is shown again it gets a position in the default DocumentTabStrip. We have a feature request regarding this type of functionality, you can subscribe for updates and cast your vote here

As a possible workaround I can suggest saving the RadDock layout to XML whenever a document window gets hidden and when it appears load the already saved layout. Have in mind that this approach has a number of limitation because the layout would be saved when only a document window is hidden:
public partial class Form1 : Form
{
    private bool isRestored = false;
 
    public Form1()
    {
        InitializeComponent();
 
        this.Load += Form1_Load;
        this.radDock1.DockStateChanged += radDock1_DockStateChanged;
        this.radDock1.DockStateChanging += radDock1_DockStateChanging;
    }
 
    private void radDock1_DockStateChanged(object sender, DockWindowEventArgs e)
    {
        if (isRestored)
        {
            this.radDock1.LoadFromXml(@"..\..\..\layout.xml");
            isRestored = false;
        }
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (DockWindow tW in this.radDock1.DockWindows.GetWindows(DockState.TabbedDocument))
        {
            tW.CloseAction = DockWindowCloseAction.Hide;
        }
    }
 
    private void radDock1_DockStateChanging(object sender, DockStateChangingEventArgs e)
    {
        if (e.NewWindow is DocumentWindow)
        {
            if (e.NewDockState == DockState.Hidden)
            {
                this.radDock1.SaveToXml(@"..\..\..\layout.xml");
            }
            else if (e.NewDockState == DockState.TabbedDocument && e.NewWindow.DockState == DockState.Hidden)
            {
                isRestored = true;
            }
        }
    }
 
    private void radButton1_Click(object sender, EventArgs e)
    {
        DockWindow[] hiddenWindows = this.radDock1.DockWindows.GetWindows(DockState.Hidden);
        foreach (DockWindow window in hiddenWindows)
        {
            window.Show();
        }
    }
}

As another approach I can also suggest using the AddDocument method and specify a DockPosition for each DockWindow that you want to show back.

I hope this information is useful. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Dock
Asked by
Hugues
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Hugues
Top achievements
Rank 1
Share this question
or