In my project I have WPF Application that play videos (ContentControl), It receive the videos from third party projects - they return the control as Winform Controls.
I Implemented a 3rd party project that has a certain WPF control (MedialElement). Since the project is via API, I must return win form control and not a wpf control.
How i solved this issue ?
I wrapped the WPF control inside an ElementHost object:
MediaElement newMediaElement = new MediaElement();
newMediaElement.Source = new Uri(@SomePath");
ElementHost mediaElementWrapper = new ElementHost(); //Wrap the media element
mediaElementWrapper.Child = newMediaElement;
And i return the mediaElementWrapper to my consumer.
So now in the main WPF player, I get this ElementHost and do the following:
ElementHost elementHost = (ElementHost)session.PlayerControl;//PlayerControl is winform control
var extractedMediaElement = elementHost.Child as MediaElement;
elementHost.Child = null;//Disconnect the control - otherwise we get exception
return extractedMediaElement;
Everything is working fine !
My question is, Why in my WPF Play application i must reference System.Windowns.Forms, Why referece for WindowsFormsIntegration and WindowsBase is not enough ?
EDIT:
I see the inheritrance heirarchy (as documented): System.Windows.Forms.Control System.Windows.Forms.Integration.ElementHost
But does the WindowsormIntergration should be the only assembly that both WPF and winform know ? why does the WPF application needs to know the entire System.Form
ElementHostderives fromControl. Otherwise how could the compiler know e.g. which methods are legal to call on an instance and what their signatures are? And how could the runtime actually make the call? - Jon