DockableContent Close ???

Oct 22, 2010 at 5:15 PM

I am using Avalon 1.3.3571.0 in a WPF application and have a question regarding DockableContent.Close(). I read the discussion in earlier threads but could find an answer:

 

"If DockableContent.IsCloseable property is false (as default) content is  not closed but only hidden (same effect as calling Hide() method). 
In the latter case it's removed from the controls tree and it's not more present under DockingManager.DockableContents list.
If forceClose is true, IsCloseabled state is not considered."

Ok, the 'X' hides rather than closes a DockableContent. But how to close a DockableContent ?

 

Let's assume that I have MyDockableContent and I want to be able to init multiple instances of it and pressing the 'X' should close the active MyDockableContent in question. I can include a StateChanged event handler, check the state and close MyDockableContent if it is hidden. But that does not work! If I check dockingManager.DockableContents.Count the count does not decrease, it increases with each instance.

Any help would be highly appreciated since I like this control.

Here is a simple code:

 

private static DockingManager dockingManager;

public static void ShowMyDockableContent(DockingManager dockManager)
{
	dockingManager = dockManager;
	
	MyDockableContent dockableContent = new MyDockableContent();
	dockableContent.IsCloseable = true;
	
	dockableContent.StateChanged += new System.Windows.RoutedEventHandler(dockableContent_StateChanged);

	dockableContent.Show(dockManager);
}

static void dockableContent_StateChanged(object sender, System.Windows.RoutedEventArgs e)
{
	if (sender.GetType().BaseType == typeof(DockableContent))
	{
		DockableContent dockableContent = (DockableContent)sender;
		if (dockableContent.State == DockableContentState.Hidden)
		{
			dockableContent.Close(true);
		}
	}
	Console.WriteLine("Count: " + dockingManager.DockableContents.Count);
}

 

 

Oct 22, 2010 at 5:47 PM

Life can be so easy, just got it. There is a HideOnClose (default = true), so the whole code shrinks to:

public static void ShowMyDockableContent(DockingManager dockManager)
{
	MyDockableContent dockableContent = new MyDockableContent();
	dockableContent.IsCloseable = true;
	
	dockableContent.HideOnClose = false;

	dockableContent.Show(dockManager);
}