Windows user control hosted in Avalon Docking WPF control

Jun 25, 2012 at 11:04 PM

Hi,

I tried the control and it seems to be working OK for WPF.

I face the following scenario. There is already developed user control, which I want to host in WPF docking control. Then that docking control will hosted inside of the main windows form. 

The problem is that I can not host my windows user control in the WPF docking control, I am getting error message. 

Can you please either post a sample of how it can be done or confirm that it is in fact impossible under the circumstances.

Thanks!

Jun 25, 2012 at 11:21 PM

You can use your wpf usercontrol inside a LayoutDocument or a LayoutAnchorable

<avalonDock:LayoutDocumentPane >
  <avalonDock:LayoutDocument ContentId="document" Title="Document">
    <myUserControlNamespace:myUserControl/>
  </avalonDock:LayoutDocument>
</avalonDock:LayoutDocumentPane>
<avalonDock:LayoutAnchorablePane>
    <avalonDock:LayoutAnchorable ContentId="anchorable" Title="Anchorable">
        <myUserControlNamespace:myUserControl/>
    </avalonDock:LayoutAnchorable>
</avalonDock:LayoutAnchorablePane>

instead if you have a windows form usercontrol you can host it inside a WindowsFormsHost as explained in the AvalonDock.TestApp that is provided with the source code in the download section.

Jun 26, 2012 at 12:39 AM

Thanks a lot for the reply!

I was following the example in the sample. The only difference I have in my project is that windows form user control should be hosted in the WPF control, not WPF form.  So I did pretty much the same as in the example and it did compile well. But during the run time I am getting error in the Program.cs in the line Application.Run(new Form1()); - it says that the object is not set to the instance of the object.

 

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);           
            Application.Run(new Form1());
        }
    }

Here is what I have in the WPF control:

 

<UserControl x:Class="Avalon.WPF"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:winformsIntegration="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
             xmlns:avalondock="http://avalondock.codeplex.com" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

        <avalondock:DockingManager Grid.Row="1" x:Name="dockManager" >
          
            <avalondock:LayoutRoot >
                <avalondock:LayoutPanel Orientation="Horizontal">
                    <avalondock:LayoutAnchorablePane DockWidth="100">
                        <avalondock:LayoutAnchorable x:Name="winFormsWindow" Title="WinForms Window" ToolTip="My WinForms Tool">
                            <winformsIntegration:WindowsFormsHost x:Name="winFormsHost"/>
                        </avalondock:LayoutAnchorable>
                    </avalondock:LayoutAnchorablePane>                   
                </avalondock:LayoutPanel>          
            </avalondock:LayoutRoot>
            
        </avalondock:DockingManager>
        
    </Grid>
</UserControl>

An this is the code behind for it:

using AvalonDock.Layout;

namespace Avalon
{
    /// <summary>
    /// Interaction logic for WPF.xaml
    /// </summary>
    public partial class WPF : UserControl
    {
        public WPF()
        {
            InitializeComponent();
            winFormsHost.Child = new UserControl1();
        }
    }
}
I have got a feeling that something trivial is missing here. I would appreciate if you could advise.

Thanks!

Jun 26, 2012 at 6:22 PM

without using code behing you could use only xaml

<avalondock:DockingManager Grid.Row="1" x:Name="dockManager" >
          
            <avalondock:LayoutRoot >
                <avalondock:LayoutPanel Orientation="Horizontal">
                    <avalondock:LayoutAnchorablePane DockWidth="100">
                        <avalondock:LayoutAnchorable x:Name="winFormsWindow" Title="WinForms Window" ToolTip="My WinForms Tool">
                            <winformsIntegration:WindowsFormsHost x:Name="winFormsHost">
                               <MyNamespace:MyUserControl/>
                            </winformsIntegration:WindowsFormsHost>
                        </avalondock:LayoutAnchorable>
                    </avalondock:LayoutAnchorablePane>                   
                </avalondock:LayoutPanel>          
            </avalondock:LayoutRoot>
            
        </avalondock:DockingManager>

Jun 26, 2012 at 6:23 PM

try this approach but it will be the same, I don't know where could be the problem, you could post the entire solution project

Jun 26, 2012 at 6:52 PM
Edited Jun 26, 2012 at 7:00 PM

Hi mach22,

I tried the approach you suggested, the issue seems to be persistent.

I am posting my project under "issue tracker" section, it is called Avalon (it is posted already).

Please let me know if it is fixable.

Thanks!