我正在創建一個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.
如何解決這個問題?
這個答案應該可以幫助你:http://stackoverflow.com/questions/11435781/a-binding-can-only-be-set-on-a-dependencyproperty-of-a-dependencyobject – alessalessio