I am creating an MVVM application.
In my model I need handle to a System.Windows.Forms.Panel that is being displayed in the View. My idea is to create this Panel in the ViewModel and then from one side - bind the View to it, on the other side, pass its handle to the model.
I've got an WindowsFormsHost control:
<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>
And I would like to bind it's Child property with my RenderPanel provided by 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
}
However, I am getting an error saying that:
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.
How to fix this?