2016-07-22 3 views
3

MVVM 응용 프로그램을 만들고 있습니다. 내 모델에서WindowsFormsHost 하위 속성 바인딩

나는 보기에 표시되고있는 System.Windows.Forms.Panel핸들이 필요합니다. 뷰 모델에서이 패널를 만든 다음 한쪽에서에 내 생각은 - 그것은에보기를 결합 , 다른 측면에서, 모델에 그 핸들을 전달합니다.

가 나는 WindowsFormsHost 컨트롤이있어 :

<Page x:Class="Test.Views.RenderPage" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:WinForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:local="clr-namespace:Test.Views" 
     mc:Ignorable="d" 
     d:DesignHeight="800" d:DesignWidth="1200" 
     Title="Page1"> 

    <DockPanel> 
     <WindowsFormsHost x:Name="winformsHost" Child="{Binding RenderPanel}"/> 
    </DockPanel> 
</Page> 

을 그리고 나는 그것이 뷰 모델에서 제공하는 내 RenderPanel와 아이 속성의 결합하고자하는

public ObservableObject<System.Windows.Forms.Panel> RenderPanel { get; private set; } 

public VideoRecorderViewModel() 
{ 
    RenderPanel = new System.Windows.Forms.Panel(); //Bind it here 
    var model = new Model (RenderPanel.Handle); pass it to the model 
} 

그러나, 나는 없다는 오류를 얻고있다 :

System.Windows.Markup.XamlParseException: 
A 'Binding' cannot be set on the 'Child' property of type 'WindowsFormsHost'. 
A 'Binding' can only be set on a DependencyProperty of a DependencyObject. 

해결 방법?

+0

이 답변은 당신을 도울 것입니다 : http://stackoverflow.com/questions/11435781/a-binding-can-only-be-set-on-a-dependencyproperty-of-a- dependencyobject – alessalessio

답변

3

오류 자체는 설명입니다. Workaround for inability to bind to a property that belongs to a WindowsFormsHost Child object in C#/XAML app?

또는 당신은 사용하여 포장 수 : 당신은 WPF WindowsFormsHost 컨트롤의 자식 객체에 속하는 속성에 바인딩 할 수 없습니다

당신은 몇 가지 연결된 속성을 가진 클래스를 만들 수

이를 달성하기 위해 ContentControl은 여기에 있습니다 : Created Bindable WindowsFormsHost, but child update is not being reflected to control

+0

고맙습니다. 위에 링크 된 ContentControl과 함께 솔루션을 사용했습니다. 그것은 매력처럼 작동합니다. – Zwierzak