Following your example of integrating Prism with the dock manager, I wanted to add a thing that it was currently lacking: the ability to restore closed documents.
Not without trouble to be honest, I finally got something to work:
So basically, in the behavior, I listen to the region's active views collection changes and directly work with the docking manager:
private void RegionActiveViewsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
var manager = HostControl as DockingManager ?? throw new InvalidCastException();
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
{
foreach (var element in e.NewItems?.Cast() ?? throw new NullReferenceException())
{
var state = DockingManager.GetState(element);
switch (state)
{
case DockState.Dock:
throw new NotImplementedException();
case DockState.Float:
throw new NotImplementedException();
case DockState.Hidden:
DockingManager.SetState(element, DockState.Document);
break;
case DockState.AutoHidden:
throw new NotImplementedException();
case DockState.Document:
manager.ActiveWindow = element;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
break;
}
}
(complete example: https://github.com/aybe/SfDocking)
Question:
Is this the correct way to restore windows that have been closed by the user?
Thank you