C# WPF, Best practice to "refresh" plugin if user starts a new Rhino Doc

Hello everyone,
It’s been a while since I’ve posted - have stumbled across an interesting question that I need some help with.

I am building a plugin that draws from various data sources, some of which include preference-like information that occur within the WPF environment (information related to interface etc). I’m trying to find the simplest and cleanest way to ensure that all of the preference information is destroyed if a user starts a new project.

At first thought it seems that the simplest / most fool proof method would be to simply destroy the WPF and force the user to reload it, (and or or automatically reload it for them after the WPF is destroyed).

Is there a simple way to destroy the WPF?

For example the creation process is:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    Window mwpfapp = new MyWPFApp();
    new System.Windows.Interop.WindowInteropHelper(mwpfapp).Owner = Rhino.RhinoApp.MainWindowHandle();
    mwpfapp.Show();

    return Result.Success;
}

What @tree,

What is your “WPF”? Is it a modeless windows?

– Dale

I believe it is Windows Presentation Foundation. A windows UI framework relatively newer than WIndows.Forms.

Yeah I am very familiar with the acronym. I was (trying to) ask what kind of window he had…

– Dale

Oh, sorry…

Not sure what you are trying to accomplish by destroying a Window. But I’d recommend an MVVM approach, binding your UI data to a ViewModel.

That way as you make changes to your data model, the UI will update automatically.

For this we often use MvvmLight NuGet package.

You can hook into Rhino’s Document events, and when a new document is created you can call a method on your ViewModel to reset the data as needed.

Our entire application is WPF, and we position Rhino within it, but communicate to our Rhino Plugin over WCF, we have callback events that are raised for various rhino events such as a new document being created.

I’d be happy to put a small sample together if you need help.