Can RhinoCommon be used with WPF

I think that once you give the mainview the viewmodel, all nested controls inherit the DataContext of the main view.

1 Like

Yes, Thank you soo much. It’s okey now :grinning:

1 Like

I am also sorry for opening this once again, but I think that I got a similiar issue.

I have an UI that works pretty good in a plain WPF-Application.
Now I want to implement that in my Rhino Plug In and I get that error

I just added the App.xaml from the WPF-Application.
That is already a thing I am not quite sure about if that is possible.

Any suggestions would be very much appreciated! :slight_smile:

As far as I know, you have to change your “windows” to “usercontrol” and dont touch app.xml.
If it is your first wpf plugin, its better to take a look at this sample:

Thanks, for the reply.
Ok, I won’t experiment with the App.xaml

I worked my way through the sample and there they also used a Window (at least in the WpfDialog)
In UserControl there is also no way to set the DataContext like this:

    <Window.Resources>
        <DataTemplate x:Name="redViewTemplate" DataType="{x:Type viewModel:RedViewModel}">
            <view:RedView DataContext="{Binding}"/>
        </DataTemplate>
    </Window.Resources>

Or do you know another way to set the data context?

I don’t get the error that the ViewModel does not exist in the namespace, it surely does …

Its common to set the Data Context in a Windows’s Code Behind.

The window constructor in code behind

public MainWindow(IMainViewModel mainViewModel)
{
     this.DataContext = mainViewModel;
     InitializeComponent();
}

Rhino Command

    //Create Main WindowViewModel
    var mainViewModel = new MainViewModel();

    //Create Main Window with mainViewModel
    var mainWindow = new MainWindow(mainViewModel);

    //Create Helper to attach Rhino window(IWin32Window) as owner of Main Window(wpf)
    WindowInteropHelper helper = new WindowInteropHelper(mainWindow);
    helper.Owner = RhinoWinApp.MainWindow.Handle;

    //Open Window
    mainWindow.Show();
1 Like