Hi,
indeed we have a whole bunch of workarounds in place to make sure everything works. But this problem is slighly different as parts of Actipro already understand correctly where the focus is. The key here is that when you click inside some WindowsForms control the rafting window gets focused, and it's IsActive dependency property changes correctly.
So basically here is our workaround:
public class RaftingWindowIsActiveAdjuster
{
private static readonly DependencyPropertyDescriptor IsActiveDependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(
DockingWindowContainer.IsActiveProperty,
typeof (DockingWindowContainer));
private static readonly PropertyInfo IsActiveProperty = typeof (DockSite).GetProperty("ActiveWindow");
private readonly DocumentWindow documentWindow;
private readonly DockingWindowContainer dockingWindowContainer;
private RaftingWindowIsActiveAdjuster(DocumentWindow documentWindow, DockingWindowContainer dockingWindowContainer)
{
this.documentWindow = documentWindow;
this.dockingWindowContainer = dockingWindowContainer;
IsActiveDependencyPropertyDescriptor.AddValueChanged(dockingWindowContainer, (s, args) => OnIsActiveChanged());
}
private bool IsActive
{
get { return IsActiveDependencyPropertyDescriptor.GetValue(dockingWindowContainer).As().ValueOrDefault; }
}
public static void AdjustIsSelected(IRaftingWindowAdapter raftingWindowAdapter)
{
raftingWindowAdapter.DocumentWindow
.WhenHasValue(d => raftingWindowAdapter.DocumentWindowContainer.WhenHasValue(c => new RaftingWindowIsActiveAdjuster(d, c)));
}
private void OnIsActiveChanged()
{
if (IsActive)
{
IsActiveProperty.SetValue(
documentWindow.DockSite,
documentWindow,
BindingFlags.NonPublic | BindingFlags.Instance,
null,
null,
CultureInfo.InvariantCulture);
}
}
}
This said maybe your logic for detecting ActiveWindow could also be based on the IsActive state of DocumentWindow itself?
As a side note in case other people are interested, to ensure correct focus we:
- Focus the WindowsFormsHost in case of clicks on the DocumentWindow (otherwise the selected style is not applied correctly)
- Focus the WindowsFormsHost in case of clicks on the RaftingWindow (same issue as above)
- Do some complex logic to handle Ctrl+Tab (for similar reasons)