2
저는 윈도우 폼 어플리케이션에 일반 패널을 가지고 있고 그 안에 WPF에있는 스택 패널을 추가하고 싶습니다.스택 윈도우를 윈도우 폼으로 호스팅하기
스택 패널은 내부에 2 개의 확장기 컨트롤로 구성되어야합니다.
요소 호스트를 사용하여 창 패널에서 스택 패널과 확장기 컨트롤을 사용하고 있습니다. 더 컨트롤 내 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.
:
다음 코드를 사용하고 있습니다.
ElementHost host = new ElementHost();
StackPanel wpfPanel = new StackPanel();
host.Child = wpfPanel;
//panel1 is Windows Forms Panel
panel1.Controls.Add(host);
나는 당신이 WPF 사용자 정의 컨트롤에 필요한 UI를 생성 한 후이 ElementHost에 추가 할 것을 권 해드립니다 : 기능 여기
내가 그것을 acheive하는 방법 WPF 스택 패널에 동적으로 컨트롤을 추가 할 버튼 클래스를 창 형태로 올바른 네임 스페이스를 사용하고 있습니다. –
@DARASANDY 답변을 업데이트했습니다. –