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

Event to detect condition of a pane becoming a floating pane

8 Answers 352 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Nick Polyak
Top achievements
Rank 1
Nick Polyak asked on 19 Mar 2010, 04:50 PM
There is a RadDocking.PaneStateChanged event, but it does not carry information about the old and new states. I need to detect a condition when a Pane becomes a floating pane. How can it be done?
Also, perhaps there is a preview event to cancel the change?
Thanks
 

8 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 24 Mar 2010, 10:57 AM
Hi Nick,

Thank you for your interest in our controls.

You can use the RadDocking.PaneStateChanged event to detect if the pane becomes Floating like so:

private void RadDocking_PaneStateChange(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    var pane1 = e.OriginalSource as RadPane;
    if (pane1.IsFloating)
    {
       //The Pane is Floating.
    }
}

But, unfortunately, there is no way to cancel the Floating, except using the CanFloat="False" property of the Pane.

If you need further assistance please feel free to contact us again.

Greetings,
Konstantina
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.
0
Andrew Thompson
Top achievements
Rank 1
answered on 27 Dec 2010, 12:06 AM
+1 from me. 

I'd like to be able to cancel a float under certain conditions. The condition is I have a docking manager where I want to rearrange tabs as document only. Setting CanFloat=false on these does not allow me to dock them at all!! So I have to have them floatable to dock as tabbed documents

But - when I float I would like to cancel and revert to the original position. 
0
Konstantina
Telerik team
answered on 30 Dec 2010, 05:37 PM
Hello Andrew,

Could you please go through this blog post: http://blogs.telerik.com/silverlightteam/posts/09-12-29/using_compass_indicators_properties_for_telerik_s_docking_control_for_silverlight_and_wpf.aspx
In it is explain how to implement conditional docking, which might help you in your case.

Hope this helps. If you have further questions please let us know.

Best wishes,
Konstantina
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Andrew Thompson
Top achievements
Rank 1
answered on 30 Dec 2010, 07:15 PM
Hi there, 

Thank you for your reply. Unfortunately though it doesnt answer my question. The problem I face is that I want certain tabs to be docked as document only but in order to acheive this I have to set CanFloat = true. This means I can float and dock as document. 

The case in question is I have nested dock managers (the inner docking manager must have only rearrangable tabs)

I have achieve a rather hacktastic workaround to cancel the float of a RadPane, here's the code. 

Note this wont compile if you paste it verbatim as its dependent on my UI hierachy, however the comments should show what you would need to change to get this to work. 

Its a bit of a hack, basically on start float a pane it registers a potential "lost pane". Then on mouseup it fires an event with a 100ms callback. If the pane is still floating after 100ms it docks it back in the document host. 

As you can see I am using reflection to implement my own MoveToDocumentHost, as I wish to specify which one (there are two in my application, an inner and outer. Its the inner one I want to set this one)

   -- Hint, it would be nice to have an overload of MoveToDocumentHost that specified which Docking Manager ;-)

To use the FailedComponentFloatExtension, in the code behind of my main window I simply typed this._extension = new FailedComponentFloatExtension(this.DockingManager);

   -- Hint, it would be nice to have CanFloat = false but CanDockAsDocument = true and tabbed docking to work!! 

Cheers, 

/// <summary>
/// Helper class to prevent a bug where the user could drag a component and drop it without docking, which would
/// cause the component to disappear
/// </summary>
public class FailedComponentFloatExtension : RadDockExtensionBase
{
    private RadComponentPane _lostFloatingPane;
 
    public FailedComponentFloatExtension(RadDocking dockingManager) : base(dockingManager)
    {
        DockingManager.PaneStateChange += new EventHandler<RadRoutedEventArgs>(DockingManager_PaneStateChange);
        DockingManager.PreviewMouseUp += new MouseButtonEventHandler(DockingManager_PreviewMouseUp);
    }
 
    private void DockingManager_PreviewMouseUp(object sender, MouseButtonEventArgs e)
    {
        // On mouse up we see if we have a potential lost floating pane
        if (_lostFloatingPane == null)
            return;
 
        // Fire an event after 100ms. If the lost floating pane is still lost, redock it in the document host for the selected document
        var timer = new OneShotTimer(100);
        timer.Expired += (s, args) =>
        {
            // If no longer lost, return
            if (_lostFloatingPane == null)
                return;
 
            // The following code is equivalent to calling _floatingPane.MoveToDocumentHost()
            // but on the current selected document's dockmanager
            //
            // If you call MoveToDocumentHost directly the floating pane which gets dropped will replace the document tab control
            // so we must inject it into the document docking control
            //
            // Note this fix is quite dependent on the hierarchy of RadTabControl -> WorkspaceDocumentView -> DockingManager -> DocumentHost
            try
            {
                Log.Debug("Restoring lost floating pane: " + _lostFloatingPane.Name);
                var documentTabControl = DockingManager.DocumentHost as RadTabControl;
                var selectedDocument = documentTabControl.SelectedItem as WorkspaceDocumentViewModel;
                var componentDockingManager = (selectedDocument.View as WorkspaceDocumentView).ComponentDockingManager;
                var documentHost = ReflectionUtil.GetNonPublicField<DocumentHost>(componentDockingManager, "documentHost");
                documentHost.AddPane(_lostFloatingPane);
            }
            catch (Exception caught)
            {
                throw new InvalidOperationException("An error occured trying to re-dock a lost floating pane", caught);
            }
        };
        timer.Start();
    }
 
    private void DockingManager_PaneStateChange(object sender, RadRoutedEventArgs e)
    {
        _lostFloatingPane = null;
 
        var pane = e.OriginalSource as RadComponentPane;
         
        if (pane != null)
        {
            // When a pane goes floating, store it as a potential lost floating pane
            // else null it (e.g. when the pane is successfully docked)
            _lostFloatingPane = pane.IsFloating ? pane : null;
        }
    }
}
 
/// <summary>
/// Specific pane type to host Components in the workspace
/// </summary>
public class RadComponentPane : RadPane
{
    public RadComponentPane()
    {
    }
}
 
/// <summary>
/// Provides a timer that ticks only once after a specified interval in milliseconds
/// </summary>
public class OneShotTimer
{
    private readonly Timer _timer;
 
    public EventHandler<EventArgs> Expired;
 
    public OneShotTimer(int intervalMs)
    {
        _timer = new Timer();
        _timer.Interval = intervalMs;
        Expired += (s, e) => { };
        _timer.Tick += new EventHandler(Timer_Tick);           
    }
 
    public int Interval
    {
        get { return _timer.Interval; }
        set { _timer.Interval = value; }
    }
 
    public void Start()
    {
        _timer.Enabled = true;
        _timer.Start();
    }
 
    private void Timer_Tick(object sender, EventArgs e)
    {
        _timer.Stop();
        _timer.Enabled = false;
 
        Expired(this, EventArgs.Empty);
    }
}
 
public abstract class RadDockExtensionBase
{
    private readonly RadDocking _dockingManager;
 
    public RadDockExtensionBase(RadDocking dockingManager)
    {
        _dockingManager = dockingManager;
    }       
 
    public RadDocking DockingManager { get { return _dockingManager; } }
}
0
Konstantina
Telerik team
answered on 05 Jan 2011, 02:50 PM
Hi Nick,

Since putting a Docking control into another one is not supported, there might be some unexpected behaviour. I can suggest you only to use the MoveToDocumentHost without a parameter, as the Pane belongs to one of the RadDocking controls and it is not expected to be able to be moved to the other Docking.

Please let us know if you have any other questions.

Regards,
Konstantina
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Frank
Top achievements
Rank 1
answered on 19 Aug 2011, 12:21 PM
Hi,
I am really sorry but in my situation the PaneStateChanged event is not firing when I tear out a pane to make it floating. It fires when I dock it back in. I'm in a corner now because I can't see any way to notice when a pane becomes floating.
0
Konstantina
Telerik team
answered on 23 Aug 2011, 03:42 PM
Hi Frank,

I am sorry, but could you please explain more about the issue that the event is not firing when a pane is made floating? Initially, the event fires by every change of the state of any of the panes in the Docking control. I am afraid there is no other way to detect if a pane is made floating instead of using this event.

All the best,
Konstantina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Frank
Top achievements
Rank 1
answered on 24 Aug 2011, 03:51 PM
Well, I suppose I would have to try and reproduce. I don't have the code here.
My workaround has been to inherit from RadPane and override the OnStateChanged method, which did fire reliably when the Pane went e.g. floating. When I have access to the code I'll try to post some more info.
Tags
Docking
Asked by
Nick Polyak
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Andrew Thompson
Top achievements
Rank 1
Frank
Top achievements
Rank 1
Share this question
or