Is it possible to add another Windows form inside MainWindow form using WPF C#?

DINESH KUDALE 6 Reputation points
2021-05-19T07:47:22.837+00:00

In MainWindow.xaml:

<avalonDock:LayoutDocument x:Name="docBlock1" ContentId="contentBlock1" Title="Block 1">  
           <StackPanel x:Name="spBlock1" Loaded="spBlock1_Loaded" />  
         </avalonDock:LayoutDocument>  

It is a 'Block1' tab window inside 'DocingManager' of MainWindow. I have implemented AvalonDock inside MainWindow for docking purposes.

----------

In MainWindow.xaml.cs

private void spBlock1_Loaded(object sender, RoutedEventArgs e)  
            {                          
            WindowInteropHelper windowHwnd = new WindowInteropHelper(this);  
            W5.EditLD _m_Ctrl = new W5.EditLD(); //this is third party control.  
            IntPtr handleD = _m_Ctrl.GetHandle();  
            IntPtr hWnd = windowHwnd.Handle;  
            //_m_Ctrl.CreateWnd() creates control above the Mainform.   
            bCreate = _m_Ctrl.CreateWnd(WinAPI.CWnd.WS_VISIBLE | WinAPI.CWnd.WS_BORDER | WinAPI.CWnd.WS_CHILD, 0, 0, 100, 100, hWnd, IDC_MAIN); //It's Definition: public bool CreateWnd(UInt32 dwStyle, int x, int y, int width, int height, IntPtr hWndParent, UInt32 iID)              
            }  

private void spBlock1_SizeChanged(object sender, SizeChangedEventArgs e)  
        {  
//_m_Ctrl.MoveWindow() will move this control as per MainWindow resizes.  
            _m_Ctrl.MoveWindow(279, 245, 1300, 740); //Here, I have passed Window's x, y, width & height parameter manually. It's Definition: public void MoveWindow(int iX, int iY, int iWidth, int iHeight)  
        }  
  

We have DLL of this control. We don't have any source code for this control. My application is in WPF C#. I am calling WindowInteropHelper() inside my WPF project's event. The purpose of this method is to add one user control over the the form.
But this WindowInteropHelper() takes only one parameter and it must be 'Window' parameter. Please, see below-attached image.
Is it possible to add dynamically x, y, width & height parameter ( from screen (0,0) point ) of 'spBlock1' or 'docBlock1' to change this control according to resizing of the 'spBlock1' or 'docBlock1' ?

----------

97730-this.jpg

----------

But I want to use the same control over my 'Block 1' tab. But in this WindowInteropHelper() method call, I have passed 'this' keyword. 'this' is pointing to MainWindow. Hence control will see outside of the 'Block 1' tab. Is it possible to show this control inside the 'Block 1' tab? How can I achieve it? Is it possible to add another 'Window' form inside that 'Block 1'? Then I will pass this added new form in place of 'this' keyword to achieve my task.
Thanks in advance.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,687 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
772 questions
{count} vote