Embedding a Rhino.UI.Controls.ViewportControl into a xaml form

I have been trying to embed a Rhino Viewport into my XAML form. I’m thinking the only way to do this will be to create my form with a blank square and add the ViewportControl in during runtime.

I have had a read through and play with SampleCsEtoViewportCommand which was very helpful and tried to add it to my project, this lead me to Eto and as such I have referenced in Eto.dll from the Rhino 7 WIP Folder because the NuGet package seems to have issues.

// SampleCsEtoViewportCommand

`internal class SampleCsViewportForm : Dialog
{
public SampleCsViewportForm()
{
Title = “Rhino Viewport in an Eto Control”;
Resizable = true;
var viewport_control = new
{
new Rhino.UI.Controls.ViewportControl {Size = new Size(400, 200)},
new Rhino.UI.Controls.ViewportControl {Size = new Size(400, 200)}

  };
  Content = new StackLayout
  {
    Padding = new Padding(2),
    Spacing = 5,
    HorizontalContentAlignment = HorizontalAlignment.Stretch,
    Items =
      {
        viewport_control[0],
        viewport_control[1]
      }
  };
}

}

I have a read through the Eto Wiki on GitHub and found no help in the XAML section XAML Tips & Tricks but I did find a section for how to embed Eto.Forms into another application Embed Eto Forms

However I got stuck there on trying to find more on the .ToNative() property that seems to convert an Eto Form to a Windows Form.

System.Windows.Forms.Control myEtoControlAsWinForms = eto.ToNative(true);

I assume I could replace eto with the new StackLayout I created earlier but that doesn’t seem to work.

Thanks

It is possible to “host” WindowsForms controls in a WPF XAML layout using the WPF WindowsFormsHost element. No need to use Eto I think.

See https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf-by-using-xaml for more details.

This is very helpful, thankyou Menno!
Although it doesn’t solve everything as the Eto Control Is not a Windows Control and I need to cast/convert it somehow using the .ToNative(true)

Hey @dale, as you created the SampleCsEto and SampleCsWpf projects do you have any ideas?

Hi @csykesm

Let me know if the attached is helpful.

SampleWpfViewport.zip (26.2 KB)

– Dale

Thanks @dale,

that sample works perfectly!
I’ll probably use this WindowsFormHost plenty more in the future too :smiley:

@dale When bringing in RhinoInside nuget package v7.0.0 RhinoWindows.dll does not get copied into the Bin folder. RhinoInside expects the Version=8.0.0.0, Culture=neutral, PublicKeyToken=552281e97c755530. The nuget package RhinoWindows 8.0.21131.12305-wip does not seem to produce the RhinoWindows.dll in the Bin folder either. The version in the Rhino folder is 7.4. What am I doing wrong? Thanks

It sounds like you got nuget packages installed for Rhino 8. I would recommend using the Rhino 7 version.

You don’t want RhinoWindows to be copied to your bin folder. RhinoInside loads Rhino as a library from its installed location and gets other associated DLLs to also be loaded from that location.

Thanks @stevebaer ! That problem occurred even with Rhino 7 versions of Nuget Packages. However you pointed me in the right direction. The issue was that the call
RhinoInside.Resolver.Initialize();
needs to be made before WPF control is initialized. When I added this call in the window constructor, Rhino Inside is able to find the right dlls.

@Dale,

Do you have an updated example for Rhino 8 .Net Core and WPF?

Thanks,

I tried this a year back and got close but didn’t get it working.
The answer from @stevebaer was that we were ahead of the curve - hoping maybe the smoke has cleared now? Rhino.Inside .Net 7? (ETA/Feasibility) - Rhino.Inside - McNeel Forum

Hi @rafadelmolino,

This project should be V8 compatible.

– Dale

Dale,
Thanks for the update. Sorry I wasn’t more precise. Inside a plugin is working, but do you have an example from a WPF App projects?
I got that error: (process 38500) exited with code 3 (0x3).
Thanks,

Hi @rafadelmolino,

There is this WinForms app from our Rhino.Inside samples.

This should be convertible to WPF.

– Dale

Dale,

Thanks Dale. Yes, I really familiar with all the examples. In that case, is using .Net Framework 4.8, but I can not run it usign .Net Core 7.

Thanks,

Hi @rafadelmolino,

Adding this seems to work:

    static void Main()
    {
      // NOTE: Make sure to adjust your project settings so this is compiled as a 64 bit
      //       application. Rhino.Inside will only run in 64 bit

      // NEW!
      RhinoInside.Resolver.UseLatest = true;

      // Set up RhinoInside resolver at the very beginning of the application
      // This helps find and load Rhino assemblies while the program runs
      RhinoInside.Resolver.Initialize();

– Dale

How do you replace the Rhino.Inside package? Is not available for Rhino 8.

Thanks Dale.

Hi @rafadelmolino,

The resolver is open source.

@stevebaer - are there plans to update the NuGet package?

– Dale

Yes, we are actively working on a nuget update right now. Rafa has been in contact with us through email as well and we have him set up with a rhino.inside console sample that uses .NET 7.