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.
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.
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.
Again, the ActivePane will be null if the pane doesn't have keyboard focus. In the case where you just run an app, the application is active and therefore the element will actually get keyboard focus when you call Activate. When you're doing this in a unit test, its likely that the window (and possibly the application/process itself) containing the dockmanager (or any other element) is not active. This really isn't specific to XamDockManager. Try focusing any element and see if you can get its IsKeyboardFocusWithin to return true. If focus can't go into the contentpane then the ActivePane will be null.