question

DINESHKUDALE-0217 avatar image
1 Vote"
DINESHKUDALE-0217 asked DINESHKUDALE-0217 edited

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

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-wpfdotnet-wpf-xaml
this.jpg (40.3 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DINESHKUDALE-0217
Do you want to add UserControl which comes from DLL to your WPF project MainWindow?If you do, could you try to add the DLL into WPF project reference, and use below code to try?

   YourDLL.UserControlName winOpen = new YourDLL.UserControlName();
    grid.Children.Add(winOpen);// Add a Grid named grid to your Block 1 tab.

If you don't, what did you want to add in your project? Window or Page?

0 Votes 0 ·

@DaisyTian-MSFT: Thanks. Your guess is perfect.

1) I want to add UserControl which comes from DLL to my WPF project MainWindow. I have added the DLL into the WPF project's 'Debug' folder.

If I have created UserControl using WPF C#, then it is easy to implement as per your provided above 2 line's code. And it shows immediately in the 'ToolBox' window. If UserControl has not created in .Net & created using C & C++, then how can I implement it?

2) After a lot of searches on the internet, I have believed that 'Window' is the root of the Visual tree. We can not add another 'Window' as a child of this Visual tree. I have tried the Page concept, but it is also not achieved using this.

0 Votes 0 ·

0 Answers