WPF Plugin - Window Style not Working

Hello everybody,

I have a small problem with my wpf plugin. It has to do with the display of the wpf window when trying to use styles.

I have recreated the problem here, in case you want to look at it in depth.
The wpf window is opened with test.testCommand and it works fine until I try to apply a style to the wpf window (WpfApplication1.MainWindow.xaml):

<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525"
        Style="{StaticResource CustomWindow}">

Style="{StaticResource CustomWindow}" naturally links to the App.xaml file but it crashes Rhino when executed this way. If Style="{StaticResource CustomWindow}" is omitted everything works again.

The App.xaml looks like this:

<Application x:Class="WpfApplication1.App"
        <Style x:Key="CustomWindow" TargetType="{x:Type Window}">
            <Setter Property="Background" Value="Yellow"/>
            <Setter Property="BorderBrush" Value="Green"/>
            <Setter Property="BorderThickness" Value="5"/>
            <Setter Property="Foreground" Value="DarkRed"/>

I couldn’t find anything about this online. Is this a known issue or am I forgetting something?
Thanks for your help!

Keep in mind that your plug-in is DLL, not an application-level object.

To share style resources in your DLL, you will first need to create a style dictionary. Then you will need to merge the dictionary with your window resources in you xaml file.

I don’t have an example that I can point you to, but you should be able to find plenty of resources on the web.

Does this help?

– Dale

Hello @dale,
thank you for the reply.

I am looking into this syntax, but I am not sure where to place the style dictionary:

        <ResourceDictionary Source="pack://application:,,,/Resources;component/Styles.xaml"/>

I have two projects in my solution. Project1 is the Rhino plugin with a command which opens Project2 as shown below. Project2 is a wpf application. Is that maybe the problem or can it work like this?

using WpfApplication1;

namespace test
    public class testCommand : Command
        // Removed code for clarity
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            System.Windows.Window my = new WpfApplication1.MainWindow();
            new System.Windows.Interop.WindowInteropHelper(my).Owner = Rhino.RhinoApp.MainWindowHandle();
            return Result.Success;

This is the magic incantation for importing the styles

   <ResourceDictionary x:Uid="ResourceDictionary_1">
       <ResourceDictionary x:Uid="ResourceDictionary_2" Source="..\..\Themes\Generic.xaml"/>