XamDockManager DocumentContenthost.TabGroupPane

Feb 16, 2009 at 10:27 AM
Edited Feb 16, 2009 at 10:30 AM
Hi All,

I have a doc manager declared like this:
 
<
igDock:XamDockManager
  cal
:RegionManager.RegionName="{x:Static inf:RegionNames.DockingAreaRegion}"
  Margin
="5"
  Theme
="Aero"> 
    <igDock:DocumentContentHost
        <
igDock:SplitPane
            
<igDock:TabGroupPane cal:RegionManager.RegionName="{x:Static inf:RegionNames.WorkspaceRegion}"> 
            <
/igDock:TabGroupPane
        </igDock:SplitPane
   </igDock:DocumentContentHost>
</igDock:XamDockManager>

but when I try to add a UserControl to the workspace region I end up getting an error. Does the region manager only support adding controls to the docking area, or, have I missed something. The error message is "Only ContentPane or ContentPanePlaceholder maybe added to TabGroupPane"

The way I have done it at the moment is to change the user control to inherit from ContentPane and add that to the region, it works but is it the correct way to do it???

Thanks for your help

Gruff
Feb 16, 2009 at 3:11 PM
Well just a quick update, using a inherited content control works ok for showing it but causes the view to stay in memory after the document has been closed. Think I will have to look into a region adapter.
Feb 17, 2009 at 11:08 AM
Edited Feb 17, 2009 at 11:31 AM

Well I have come up with a solution that seems to work pretty well, although I had to make a few changes to the Infragistics library.

So for the benefit of anyone who might be interested and for anyone who wants to pass some helpful criticism over the code here it is.

I have the XamDockManager declared in the shell like so:

<!-- Main Dockable Area -->
<igDock:XamDockManager cal:RegionManager.RegionName="{x:Static inf:RegionNames.DockingAreaRegion}" Margin="5" Theme="Aero">
<
igDock:DocumentContentHost></igDock:DocumentContentHost>
</
igDock:XamDockManager>

In the XamDocManagerSettings I added an attached property to specify if the view should be loaded into the DocumentContentHost like so:

#region IsContentPaneInDocumentHost
/// <summary>
/// Gets the <see cref="GetIsContentPaneInDocumentHost"/> attached property.
/// </summary>
/// <param name="obj">The <see cref="DependencyObject"/> on which the property is set.</param>
public static bool GetIsContentPaneInDocumentHost(DependencyObject obj)
{
    
return (bool)obj.GetValue(IsContentPaneInDocumentHostProperty);
}

/// <summary>
/// Sets the <see cref="GetIsContentPaneInDocumentHost"/> attached property.
/// </summary>
/// <param name="obj">The <see cref="DependencyObject"/> on which the property is set.</param>
/// <param name="value">The bool that determines whether the <see cref="ContentPane"/>
/// created for a View is added to a <see cref="TabGroupPane"/> or not within <see cref="DocumentContentHost"/>.</param>
public static void SetIsContentPaneInDocumentHost(DependencyObject obj, bool value)
{
    
obj.SetValue(IsContentPaneInDocumentHostProperty, value);
}

/// <summary>
/// Identifies the IsContentPaneInDocumentHost attached property.
/// </summary>
/// <remarks>
/// The <see cref="IsContentPaneInDocumentHost"/> attached property must be set on the
/// root element in a View in order for it to be applied to the <see cref="ContentPane"/>
/// in which that View is hosted. The default value is false.
/// </remarks>
public static readonly DependencyProperty 
    IsContentPaneInDocumentHostProperty =
DependencyProperty.RegisterAttached(
        
"IsContentPaneInDocumentHost"
        
typeof(bool),
        
typeof(XamDockManagerSettings), 
        
new UIPropertyMetadata(false));

#endregion // IsContentPaneInDocumentHost

This allows me to add the attached property to the root of a UserControl

ncal:XamDockManagerSettings.IsContentPaneInDocumentHost="true"

Headers and Images and all the goodies are still able to be set through the ContentPaneProxyStyle.

I then needed to add the following the the XamDockManagerRegion.cs to make use of the attached property.

/// <summary>
/// Helper method to return the value of the attached property
/// </summary>
bool ShouldAddViewToDocumentHost(object view)
{
    
DependencyObject depObj = view as DependencyObject;

    if (depObj != null)
        return XamDockManagerSettings.GetIsContentPaneInDocumentHost(depObj); 

    return false;
}

I then modified "public override IRegionManager Add" method by adding/modifying the following lines:

// We must delay adding the SplitPane to the element tree so that the
// attached InitialLocation property can be set first, via a Style.
bool isInDocumentHost = this.ShouldAddViewToDocumentHost(view); // NEW LINE - read the attached property
dockManagerProxy.AddSplitPaneToElementTree(splitPaneProxy, isInDocumentHost); // CHANGED LINE – Method Override

// ADD VIEW TO DOCKMANAGER
bool isInTabGroup = this.ShouldAddViewToTabPaneGroup(view);

if (isInDocumentHost) // NEW LINE
        
contentPaneProxy.AllowInDocumentHost = true; // NEW LINE – Allow the view in the document host as attached property has been set


Finally I modified the XamDocManagerProxy.cs to add a method override for AddSplitPaneToElementTree

/// <summary>
/// Invoked when a <see cref="SplitPane"/> should be added to the dock manager's document host or element tree.
/// </summary>
/// <param name="splitPaneProxy">The proxy that contains the pane to be added to the document host or element tree.</param>
/// <param name="isInDocumentHost">Should this be added to the document content host</param>
public void AddSplitPaneToElementTree(SplitPaneProxy splitPaneProxy, bool isInDocumentHost)
{
    
if (splitPaneProxy == null)
        
throw new ArgumentNullException("splitPaneProxy");

    if (!isInDocumentHost)
        AddSplitPaneToElementTree(splitPaneProxy);
    
else
    {
        
DocumentContentHost documentHost = _xamDockManager.Content as DocumentContentHost;

        if (documentHost== null)
            throw new InvalidOperationException("DocumentContentHost not defined");
        
else
        {
            
if (!documentHost.Panes.Contains(splitPaneProxy.SplitPane))
                
documentHost.Panes.Add(splitPaneProxy.SplitPane);
        }
    
}
}

And that’s all there is to it, thanks for the team for developing this library, it’s certainly taken a lot of the effort out of it…

All the best.

Gruff

 

Coordinator
Feb 17, 2009 at 1:45 PM
Thanks a lot for sharing your implementation of this missing feature, Gruff.  We will integrate this fix (or some variant of it) into NCAL in the near future.
Feb 18, 2009 at 12:33 PM
Thanks for the code Gruff :-)

Is it possible to get a rough date for when Infragistics plan to integrate this fix into NCAL proper?  I might defer including Gruff's fix if Infragistics is planning to realease it bundled (and changed) soon.

/Martin
Feb 18, 2009 at 12:44 PM
Thats not a problem guys, glad to be of some use - I'm new to all the composite development so this was a good exercise for me. I plan on using their version to when its implemented and is the main reason why I just opted for the one property on the view so hopefully a quick find and replace on the views will allow me to switch to their version without to much fuss.

Gruff
Coordinator
Feb 26, 2009 at 2:42 PM
Hi,

Thanks a lot for providing this solution to the issue you found!  We are planning an upgrade of NCAL to the latest version of CAG soon, and will include this fix.
May 29, 2009 at 8:10 PM

Gruff and/or Infragistics,

Any idea how one might set this attached property via a DataTemplate?  I'm using the MVVM pattern and the views of viewmodels are DataTemplates.  However, I can't figure out how to set the XamDockManagerSettings attached properties from within the DataTemplate.