document pane closing event in avalondock

Jun 30, 2008 at 2:58 AM
I am new to wpf and started using the avalon dock for one of my project. I dont see any events raised when a document is closed in the document pane. Any link or code sniplet will be very helps

thanks a lot for helping me
Jun 30, 2008 at 8:35 AM
Hi mehrajesh, you can use the Unload event from DocumentContent to be woke when a document content is closed. For DockableContent they are simply hidden, so you can monitor the DockableContent.State to know when the content is hidden by user (see how events are reported in the EventsLog pane).
Anyway a couple of events Closing/Closed should be useful and I'm planning to add them in next release.
Thanks to you!
Jun 30, 2008 at 10:16 AM
Hello adospace !

thanks for the reply, i m planning to add closing and closed events in the DocumentPane class and in the below method of the same class

public void ExecutedCloseCommand(object sender,
            ExecutedRoutedEventArgs e)

so that whenever a document is closed, a notification can be asked to save and cancel the same

do you think is it the right place to add the closed/closing event in the document pane

i am adding a usercontrol in a documentcontent and the documentcontent is added to the document pane.

Thanks for answering again.


Jun 30, 2008 at 2:43 PM
Sure that is the right place!
Just an hint, consider the option to derive your control from documentcontent instead of UserControl (which is simply a ContentContrl placeholder).

Jul 1, 2008 at 2:43 AM
Thanks a lot..

May i know when are you planning to release the next version, i m eagerly waiting for the release.
Aug 1, 2008 at 4:06 PM
I have been working on WPF for the last two weeks and I am using the AvalonDock library.
I would like to know if there is any way to avoid closing a DocumentContent. Actually I don't even want the close button to show in the DocumentContent however if that is not possible, how can I stop the closing process especially for the home tab?
I have added the Unload event but couldn't find any variable that I can set to false regarding the closing issue.

As well, I have seen the AvalonDock sample and tried to follow some of the functions. I am having some problems with DocumentContent. If I try to open many documents and modify the way they are displayed then I decide to restore the default layout, the documents keep focused at the same location however if I do the same with DockableContent and then decide to restore the default layout, it works  well.
Is it possible to drag documents anywhere in the application then being able to restore the default layout, thus by having each document positioned at the same place as it was when I runned the application?
And how can I get all DocumentContent that are present in the application wherever they are positioned knowing that they all have the very supreme parent: DockPanel. I mean I need to able to loop over all DocumentContent.

I would appreciate any help. Thank you very much in advance.
Best Regards.



Nov 9, 2008 at 8:35 AM

About closing and closed events:

in my humble opinion, the decision about closing must make DockableContent, not DocumentPane. So it would be better to delegate it from DocumentPane; for example we can add interface for it:

  public interface ICloseable
{
bool CanClose();
}

and to modify ExecutedCloseCommand by such way:

  public void ExecutedCloseCommand(object sender,
ExecutedRoutedEventArgs e)
{
if (SelectedItem is ICloseable)
if (!(SelectedItem as ICloseable).CanClose())
return;
//... other code

And for our dockable pane (it's Dockablecontent descendant) we will implement ICloseable:

public partial class UserControl1 : DockableContent, ICloseable

{

  #region ICloseable Members

public bool CanClose()
{
// make decision here
}
#endregion
}

By this approach, we can handle and cancel closing by unified way both from attached and detached content.

Nov 9, 2008 at 9:32 AM

By the way, if I made my content as a descendant of DocumentContent, it cannot be floating. But I want floating window with possibility of control its closing behavior - and I will make it as a descendant if DockableContent. But - where I can handle closing? So, I implement ICloseable in my DockableContent's descendant and make some modifications in FloatingWindow:

  public FloatingWindow()
{
this.Closing += new CancelEventHandler(FloatingWindow_Closing);
}

public FloatingWindow(DockingManager manager) : this()
{
//save manager ref
_manager = manager;
}

void FloatingWindow_Closing(object sender, CancelEventArgs e)
{
if (_manager.ActiveContent is ICloseable)
if (_manager.ActiveContent is DockableContent)
if ((_manager.ActiveContent as DockableContent).State == DockableContentState.DockableWindow)
if (!(_manager.ActiveContent as ICloseable).CanClose())
e.Cancel = true;
}

with these and above modification I can control closing behavior both in docked and undocked content.