Interaction with the FloatingParent field during a DockStateChanged

3 posts, 1 answers
  1. Gabriele Svelto
    Gabriele Svelto avatar
    6 posts
    Member since:
    Sep 2009

    Posted 09 Feb 2010 Link to this post

     Hello,
    I have hooked an event handler to the DockStateChanged event in order to intercept the tool windows that were being detached from the dock. Once I find a tool window whose DockState has turned to Floating I adjust its size and change the border style so that the user cannot resize it anymore while it is floating. However I encountered a small problem with this approach: if I detach the tool window by clicking its tab and dragging it out of the tab strip the FloatingParent field of the DockWindow provided in the event arguments is properly set and I can alter it. However if I double-click on the tab or use the context menu to make the window floating the FloatingParent field is set to null. Curiously this only happens the first time I undock the window this way, if I dock the window again and then undock it FloatingPanel is not null anymore (the same is true if I undock the window by dragging it out of the tab strip). Is this an intended behavior or a bug? Here's my event handler code (which throws a NullReferenceException when FloatingParent is null):

    void event_DockStateChanged(object sender, DockWindowEventArgs e) 
        if (e.DockWindow.DockState == DockState.Floating) 
        { 
            // Resize a tool window to fit its contents and make it fixed-size. 
            e.DockWindow.FloatingParent.ClientSize = e.DockWindow.GetPreferredSize(Size.Empty); 
            e.DockWindow.FloatingParent.FormBorderStyle = FormBorderStyle.FixedToolWindow; 
        } 

  2. Answer
    Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 12 Feb 2010 Link to this post

    Hi Gabriele,

    Thank you for contacting us and for the detailed description of the problem you experience.

    Due to the transaction-based mechanism in RadDock TooWindow's caption double click will trigger the following events:

    - RedockTransaction - if there is a previous floating state for this window, it will be restored. That is why the second time everything works just fine - such a state already exists
    - When such a redock state does not exist, RadDock will take the default action, which in this case is to register another FloatTransaction.

    What I can see as a wrong behavior here is that the first transaction is changing the state of the window while it is still docked on RadDock. In fact it is the second transaction that does the actual floating. We will revisit this behavior and implement it properly either for Q1 2010 or for some of our next major releases (including service packs).

    For now you can hook the TransactionCommitted event of RadDock and examine the FloatingParent member of all AssociatedWindows:

    void radDock1_TransactionCommitted(object sender, RadDockTransactionEventArgs e)
    {
        foreach (DockWindow window in e.Transaction.AssociatedWindows)
        {
            FloatingWindow floatingWindow = window.FloatingParent;
            if (floatingWindow != null)
            {
                floatingWindow.ClientSize = new Size(200, 200);
                floatingWindow.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            }
        }
    }

    I would like to thank you for your time and your feedback. Do not hesitate to contact us if you have other questions.


    All the best,
    Georgi
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Gabriele Svelto
    Gabriele Svelto avatar
    6 posts
    Member since:
    Sep 2009

    Posted 12 Feb 2010 Link to this post

    Thank you for your reply, using the TransactionCommited event as you suggested worked very well and fixed my problem.
Back to Top