Hi,
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 ?
Thanks,Claudio.
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 ?
Thanks,Claudio
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.
In both cases I don't have the keyboard focus; by code I am invoking contentPane.Activate()
when created in XAML xamDockManager.ActivePane==contentPane
but in the UnitTest (where I create the xamDockManager in code),and invoke the same code it xamDockManager.ActivePane is null.
I will try to elaborate a simple case (since this is also mixed with the Composite WPF TabGroupPaneRegionAdapter I am elaborating).
Here I have a sample code (I can send you the VS solution if necessary):
XAML
<Window x:Class="XamDockManagerActivePane.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDock="http://infragistics.com/DockManager" Title="Window1" Height="300" Width="300"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <igDock:XamDockManager Grid.Row="0" x:Name="dockManager"> </igDock:XamDockManager> <Button Grid.Row="1" Click="Button_Click" Content="Generate Dock Manager"></Button> </Grid></Window>
Code Behind:
private void Button_Click(object sender, RoutedEventArgs e) { SplitPane splitPane1 = new SplitPane(); dockManager.Panes.Add(splitPane1); TabGroupPane tabGroupPane = new TabGroupPane(); ContentPane newContentPane = new ContentPane(); tabGroupPane.Items.Add(newContentPane); splitPane1.Panes.Add(tabGroupPane); newContentPane.Activate(); Console.WriteLine(dockManager.ActivePane); }
Console App:
[STAThread] static void Main(string[ args) { XamDockManager dockManager = new XamDockManager(); dockManager.BeginInit(); SplitPane splitPane1 = new SplitPane(); dockManager.Panes.Add(splitPane1); TabGroupPane tabGroupPane = new TabGroupPane(); ContentPane newContentPane = new ContentPane(); tabGroupPane.Items.Add(newContentPane); splitPane1.Panes.Add(tabGroupPane); newContentPane.Activate(); dockManager.EndInit(); Console.WriteLine(dockManager.ActivePane); }
In the XAML case it dockManager.ActivePane gives newContentPane. In the Console App case dockManager.ActivePane is null.
Well for XamDockManager Activate relates to giving the pane keyboard focus and the ActivePane is tied to whether a ContentPane contains the keyboard focus so I'm not sure what you want to consider active for your purposes.
Ok.
I just need to check that after calling contentPane.Activate() method that contentPane is indeed active.Maybe there is an easier way of doing this instead of using the xamDockManager.ActivePane property ?
Thanks again,Claudio
This is correct behavior. The XamDockManager doesn't control the WPF Framework's focused element - it just reacts to what has the keyboard focus. In your console application case, System.Windows.Input.Keyboard.FocusedElement will always be null. This isn't anything that we have any control over. You would have to put the XamDockManager into a Window, show that Window and make sure that that Window is active.