2012-04-25 2 views
1

내 응용 프로그램 내에서 작동하는 다른 Windows 양식을 호출하는 Windows 양식이 있습니다. 내가 성취하고자하는 것은이 전체 "윈도우 폼"에서 벗어나서 대신 WPF View (usercontrol)를 사용하는 것입니다. 내 양식에서 보여줄 수있는 뷰를 호출 할 수있는 방법이 있습니까? > 인수 1 : 'System.Windows.Forms.Control'Windows 내에서 xaml보기를 표시 할 수 있습니까?

답변

2

당신의 WinForm에 패널을 추가 (말할 수에 Panel1) 또한 폼로드 이벤트에서 클래스 수준

ElementHost host; 
Cars.WPF.Views.DescriptionView descView; 

에서 WPF 컨트롤을 정의 클래스 수준에서 ElementHost 정의 해야한다 :

host= new ElementHost(); 
panel1.Controls.Add(ctrlHost); //Add Element host to panel1 
descView = new Cars.WPF.Views.DescriptionView(); 
descView.InitializeComponent(); 
host.Child = descView; //Instead of adding WPF control to Winform do this 

또한 프로젝트 참조에 다음을 추가하십시오 :

PresentationCore 
PresentationFramework 
WindowsBase 
1

예, 사용 요소 호스트에 'Car.WPF.Views.DescriptionView'에서 변환 할 수 없습니다 - :

ElementHost host = new ElementHost(); 
      Cars.WPF.Views.DescriptionView descView = new Cars.WPF.Views.DescriptionView(); 
      host.Controls.Add(descView); 
      host.Dock = DockStyle.Fill; 

나는 오류가 발생합니다.

http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms

http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx

+0

나는 요소 호스트를 사용해 보았지만 그것을 좋아하지 않습니다. – Calvin

+0

exacly 무엇이 좋지 않습니다. WPF UserControl이 표시되지 않습니까? 바인딩이 작동합니까? 키보드 입력이 인식되지 않습니까? 간단한 WPF 컨트롤을 사용하여 새 양식을 시작하기 만하면 간단하게 시작한 적이 있습니까? 그게 일하게? –

+0

예제를 업데이트했습니다. – Calvin

관련 문제