I have the following code (used as part of a unit test),
xamDockManager = new XamDockManager(); splitPane = new SplitPane(); xamDockManager.Panes.Add(splitPane);
At a later step (where I don't have the xamDockManager reference, only the splitPane), I need to get the xamDockManager where the splitPane belongs. Testing splitPane.Parent gives me null. Is this correct ? Is there other way to get the associated xamDockManager if I only have the splitPane available ?
If the SplitPane is still part of the XamDockManager then you can use the attached inherited DockManager property to get to it - e.g. XamDockManager.GetDockManager(splitPane).
Maybe I am missing something but the following code, gives null for xamDockManager2
XamDockManager xamDockManager = new XamDockManager();SplitPane splitPane1 = new SplitPane();xamDockManager.Panes.Add(splitPane1);XamDockManager xamDockManager2 = XamDockManager.GetDockManager(splitPane1);
The DockManager property is an inherited attached dependency property so it would only be available once it percolated down the element chain (i.e.logical/visual tree). In that code snippet, the elements wouldn't have been processed since the control waits until the Initialized event has been invoked before processing the panes. The Initialized event of FrameworkElement is normally invoked by the baml processor while it is initializing a control and otherwise that event is fired later on by the framework (I believe when it is associated with a presentationsource but you would have to check the ms documentation to know for sure). If you are creating the control in code then maybe you can wrap the creation/initialization by calling the control's BeginInit and EndInit methods.
Calling BeginInit and EndInit methods allows me to get the xamDockManager2 in the code above.
However when activating a ContentPane (ie calling contentPane.Activate() method), xamDockManager.ActivePane is nullThis doesn't happen if xamDockMager is created in XAML code.
Any other hint or tip ?
I'm not sure at what point (with respect to its creation and with respect to the display/load state of the containing window) you are comparing the ActivePane between one created in xaml and one created in code so I cannot say why you are seeing a difference. The ActivePane is tied to the element with keyboard focus. If the ActivePane is null then you must not have keyboard focus within any content pane.