2016-07-22 133 views
3

私はMVVMアプリケーションを作成しています。私モデル私はビューに表示されているSystem.Windows.Forms.Panelハンドルが必要でWindowsFormsHost子プロパティをバインド

ViewModelにで、このパネルを作成し、一方の側からに私の考えがある - それにビューをバインド、他の側に、モデルにそのハンドルを渡します。

私はに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> 

そして、私はそれがViewModelに

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 
} 

が提供する私のRenderPanelは、しかし、私はというエラーを取得してい児施設ですバインドしたいと思います:

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

関連する問題