繁体   English   中英

在 C# 中创建时,如何使 System.Windows.Forms.Panel 填充 WPF 中的容器?

[英]How to make System.Windows.Forms.Panel fill the container in WPF when created in C#?

我试图通过使用 WinfowsFormsHost 和 System.Windows.Forms.Panel.Here 是代码在 WPF 程序上托管一个 exe:


    public void AddPuttyPage(Process process)
        {
            var picPan = new System.Windows.Forms.Panel() { 
                Dock = System.Windows.Forms.DockStyle.Fill
            };
            var winform = new WindowsFormsHost
            {
                Child = picPan,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch
            };
            //Tabs are bind to the TabControl on a xaml
            Tabs.Add(new TabItem { Header = "Tab1", Content = winform });
            process.WaitForInputIdle();

            SetParent(process.MainWindowHandle, picPan.Handle);
        }

我希望System.Windows.Forms.Panel填充容器,以便 exe 应用程序填充窗口。 我设置了Dock = System.Windows.Forms.DockStyle.Fill ,但它不起作用,面板仍然具有默认大小 100*200。

那么我应该怎么做才能让面板填充它的容器?(面板的容器是WindowsFormsHost,WindowsFormsHost是TabItem的内容,所以我希望面板实际上填充tabPage)

最后,我通过获取 tabControl.ActualHeight 和 ActualWidth 的 ActualHeight 和 ActualWidth 来做到这一点,可以通过此解决方案将 ActualHeight 和 ActualWidth 绑定到 viewModel: 第一个答案,然后像这样初始化面板:

           var picPan = new System.Windows.Forms.Panel() { 
                Height = AcutalHeight,
                Width = AcutalWidth,
                Dock = System.Windows.Forms.DockStyle.Fill
            };

最后使用ShowWindow(handle, SW_MAXIMIZE)让窗口填充面板。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM