This project is read-only.

Active DocumentContent or Focusing on DocumentContent problem

Jan 14, 2010 at 12:20 PM

Hello all,

I am currently using AvalonDock to establish a UI interface which consist of one tab, the "home" DocumentContent.
My Xaml looks something like this:

<ad:DockingManager x:Name="_dockingManager">
                <ad:DocumentPane x:Name="_documentsHost">
                    <ad:DocumentContent x:Name="docHome" Title="Home" IsFloatingAllowed="True" IsCloseable="False" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Top">

In some circumstances, I have to dynamically create a new DocumentContent. The code looks like this:

AvalonDock.DocumentContent exportContent = new AvalonDock.DocumentContent();
   exportContent.Name = contentName;
   exportContent.Title = export.Name;
   exportContent.IsFloatingAllowed = true;
   exportContent.IsCloseable = true;
   exportContent.HorizontalAlignment = HorizontalAlignment.Stretch;
   exportContent.HorizontalContentAlignment = HorizontalAlignment.Stretch;
   exportContent.VerticalContentAlignment = VerticalAlignment.Top;
   exportContent.Content = anObject;

My problem is how to show the content of the the dynamically added DocumentContent ? For the moment, a new tab is created and visible, but I always on the "home" DocumentContent.

I tried:

_documentsHost.SelectedIndex = _documentsHost.Items.Count - 1;
_documentsHost.SelectedItem = exportContent;

But nothing works, I cannot find a way to "activate" the new DocumentContent, a bit like if the user clicked on the tab name.

Could anyone help on this issue ?


Jan 29, 2010 at 2:48 PM

Found a solution !

Instead of directly focus the newly created DocumentContent, attach to the Loaded Event.

Like that we ensure everything is allright in the tree of object, adn in this delegate event focus the selected item.

Feb 23, 2010 at 4:58 PM

Hi Micky,


same problem as yours.

OK to attach to the Loaded event. But there's no Loaded event for DocumentContent, only for DocumentPane.

I guess a deeper knowledge of Avalon should help, but I have not it`!

Thanks for any help.

Mar 2, 2010 at 2:20 AM

Can I suggest the SetAsActive method?

It is a member of th DocumentContent class, inherited from the ManagedContent class.



exportContent.Content = anObject;



then you don't have to muck about with DocumentPane.Loaded, etc... or doing explicit casts to call .Focus().

Try it =) You might like it.


Apr 9, 2012 at 11:34 AM

mickynet - could you please explain a bit more about how you solved this problem? I am having the same issue.

Many thanks in advance.