【发布时间】:2015-03-11 12:23:44
【问题描述】:
我的 Windows 窗体应用程序中有一个普通面板,我想在其中添加一个 WPF 中的堆栈面板。
堆栈面板内部应包含 2 个扩展器控件。
我正在使用 Element Host 在 windows 窗体中控制堆栈面板和扩展器。
我正在使用以下代码:
ElementHost WPF_Container = new ElementHost();
WPF_Container.AutoSize = true;
ElementHost WPF_Container1 = new ElementHost();
WPF_Container1 .AutoSize = true;
ElementHost StackPanelHost = new ElementHost();
Expander expander1 = new Expander();
expander1.Header = "Pipes";
Expander Expander2 = new Expander();
Expander2.Header = "Mountings";
uc1 uc1 = new uc1(); // Object Creation for User Control-1
uc2 uc2 = new uc2(); // Object Creation for User Control-2
StackPanel Stackpanel = new StackPanel();
Stackpanel.Orientation = System.Windows.Controls.Orientation.Vertical;
WindowsFormsHost host = new WindowsFormsHost();
host.Child = uc1 ;
WindowsFormsHost host2 = new WindowsFormsHost();
host2.Child = uc2;
expander1.Content = host;
Expander2.Content = host2;
Stackpanel.Children.Add(expander1);
Stackpanel.Children.Add(Expander2);
// WPF_Container.Child = expander1;
// WPF_Container1.Child = Expander2;
StackPanelHost.Child = Stackpanel;
panel1.Controls.Add(StackPanelHost); // Adding Stack Panel to my Winform Panel.
通过在表单加载事件期间使用上述代码,我的 Windows 表单面板中没有添加任何控件。 如何实现功能
【问题讨论】:
标签: c# wpf winforms wpf-controls