views:

478

answers:

4

First I just want to say I am new to WPF, so please excuse my ignorance...

I am creating a .Net plug-in for Rhino 4.0. With the plugin I am developing a UI using WPF.

The Rhino 4.0 CAD engine is an MFC/Win32 application. The plugin will execute after the application is run, and it creates the WPF Window and then "sucks" the MFC Window into it.

So my question is, does WPF look for an App.xaml file to get to Application level resources if the hosting application isn't a WPF app?

If not, what is the best way to store application level resources?

Thanks,

Jason

A: 

my guess is it has to do with how does rhino run your plugin does it run it as a seperate process or does it just call some thing you have defined?

If it does call a function you defined then you could just put the code there that will start the window?

Petoj
+1  A: 

WPF projects will - by default - generate an entry point for your application. This entry point constructs and initializes your Application-derived class for you. If you need, you can always create your instance manually, and store application-level resources in it:

App app = new App();
app.InitializeComponent();
app.Run();

HTH, Kent

Kent Boogaart
This sounded like the best approach but when executing it cannot find any of the resources specified in the App.xaml page.I tried the "pack://,,," method, and the "component/path" method, as well as the straight path. None would work.Visual Studio could find them but at runtime they would fail.
Jason Stevenson
+1  A: 

Have you tried storing your resources at what MSDN refers to as the 'theme level'?

Within a folder called "<root>\Themes" have a file called generic.xaml.

I haven't tried this for a project that wasn't a WPF application, but the approach might work for you.

Drew Noakes
Thanks I'll give it a try soon.
Jason Stevenson
+1  A: 

App.xaml is used as a part of a partial class App : Application. If your application does not have a WPF based Application class, you can manually load dictionaries and merge with the application and create a main window and show it (access via static methods of Application class).

Code goes kind of like this.

var reader = new XamlReader();
var dictionary = reader.read("path to xaml file") as ResourceDictionary;
if (dictionary != null)
    Application.MergedDictionaries.Merge(dictionary);

var mainWindow = new MyMainWindow();
mainWindow.Show();
Danny Varod