I just spent the morning building this exact script for the project I'm working on. Here's the context version of the code:
public class WPFScopeNode: ScopeNode
{
public WPFScopeNode()
: base()
{
this.DisplayName = "Name in tree view";
var wpfFormView = new FormViewDescription
{
DisplayName = "Name of view",
ControlType = typeof(WPFHostControl),
ViewType = typeof(WPFHostFormView)
};
this.ViewDescriptions.Add(wpfFormView );
}
}
public class WPFHostFormView : FormView
{
public WPFHostFormView ()
{
this.DescriptionBarText = "WPF Host View";
}
protected override void OnInitialize(AsyncStatus status)
{
base.OnInitialize(status);
}
}
public partial class WPFHostControl : UserControl
{
public WPFHostControl ()
{
InitializeComponent();
ParentChanged += new EventHandler(WPFHostControl_ParentChanged);
}
void WPFHostControl_ParentChanged(object sender, EventArgs e)
{
if (Parent != null)
{
Size = Parent.ClientSize;
Parent.ClientSizeChanged +=
new EventHandler(Parent_ClientSizeChanged);
}
}
void Parent_ClientSizeChanged(object sender, EventArgs e)
{
if (Parent != null)
{
Size = Parent.ClientSize;
}
}
private MyWPFUserControl hostedControl;
private System.Windows.Forms.Integration.ElementHost elementHost;
private void InitializeComponent()
{
this.elementHost = new System.Windows.Forms.Integration.ElementHost();
this.hostedControl = new MyWPFUserControl();
this.SuspendLayout();
this.elementHost.Dock = System.Windows.Forms.DockStyle.Fill;
this.elementHost.Location = new System.Drawing.Point(0, 0);
this.elementHost.Name = "elementHost";
this.elementHost.Size = new System.Drawing.Size(150, 150);
this.elementHost.TabIndex = 0;
this.elementHost.Child = this.hostedControl;
this.Controls.Add(this.elementHost);
this.Name = "WPF Host View";
this.ResumeLayout(false);
}
}
source
share