WPF Hosting in Viewlets

Jul 1, 2008 at 7:03 PM
Edited Jul 1, 2008 at 7:09 PM
Hi,

I've been trying to host an open source Wpf chart control swordfishcharts in a Viewlet and was hoping that posting would help me understand my error.

My attempt was based on http://msdn.microsoft.com/en-us/library/ms742215.aspx. The code is presented below;

#light

open System
open System.Drawing
open System.Windows.Forms

open VSLabFSICore
open VSLabViewlets

#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\"
#r "WindowsBase.dll"
#r "PresentationCore.dll"
#r "PresentationFramework.dll"
#r "WindowsFormsIntegration.dll"

#r "Swordfish.WPF.Charts.dll"

open System.Windows.Forms.Integration
open Swordfish.WPF.Charts

type wpfChart() as this =
    inherit Viewlet() as base
   
    let mutable wpfCtrlHost = null : ElementHost
    let mutable wpfChart = null : TestPage
   
    do this.Load.Add( fun args ->
            wpfCtrlHost <- new ElementHost(Dock=DockStyle.Fill)
            this.Controls.Add(wpfCtrlHost)
           
            wpfChart <- new TestPage()
            wpfChart.InitializeComponent()
            wpfCtrlHost.Child <- wpfChart        
        )

let wpfChart1 = new wpfChart()
wpfChart1.Show()
Application.Run(wpfChart1)

(* End *)

This however fails to show the WPF control in the Viewlet. Replacing the class Viewlet with System.Windows.Forms.Form allows the wpfChart class to correctly instantiate.

Any idea as to what's going wrong are much appreciated.

regards,
Danny

Coordinator
Jul 2, 2008 at 9:12 AM

Danny,

the problem is that the internal of viewlets are deeply rooted in Win32 device contextes and therefore another presentation system cannot be supported directly.
Because of the retention based approach of WPF I think it is possible to develop a WPFViewlet that run inside VS in another toolwindow and hosts a WPF control (a sort of silverlight), and the F# peer would interact with the toolwindow by means of IPC (in a client-server fashion). I don't know if it is possible to do cross-process WPF applications, this should be investigated. In the doc there is a whitepaper describing the internal working.

-- Ciao,

-- Antonio


DannyAsher wrote:
Hi,

I've been trying to host an open source Wpf chart control swordfishcharts in a Viewlet and was hoping that posting would help me understand my error.

My attempt was based on http://msdn.microsoft.com/en-us/library/ms742215.aspx. The code is presented below;

...


Jul 9, 2008 at 11:03 AM
Hi Antonio,

thanks for the info here. I'll take a look at the document, but would love to see Wpf supported, as I could then develop and contribute Wpf viewlets.

regards,
Danny
Coordinator
Jul 16, 2008 at 8:13 AM
I have to figure out how to marshal WPF calls. To keep the same amount of expressivity we need to find a way to make WPF draw on a window owned by another process. I'll check that.
Aug 17, 2008 at 11:05 PM

Hi Antonio,

let me know if there's anything I can do to help here. Looking forward to the next version!

regards,

Danny
Coordinator
Sep 8, 2008 at 2:02 PM
You could investigate how to have a WPF app that renders on a window of a different process. (maybe by simply marshalling visual tree diffs... I really don't know).
Thanks Danny :)

-- Ciao,
-- Antonio