2 Replies - 1298 Views - Last Post: 02 October 2012 - 08:26 AM Rate Topic: -----

#1 Tim.Simon  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 26
  • Joined: 12-June 12

Set ResourceDictionary when loading WPF from a different project

Posted 01 October 2012 - 11:17 AM

This is a continuation of an unresolved question I had here: http://www.dreaminco...1&#entry1710111

I am posting as a new question because I believe I have narrowed the issue down to a ResourceDictionary problem, and I decided that this new information would never be seen.

The basic issue is that I have a WPF project that works fine when set as the default startup project, but if I try to call it from another application (Windows Tray app), some of the data does not display correctly. These two applications are in separate projects but the same solution.

When I set the WPF up as the default startup project, the ResourceDictionary is loaded from App.xaml. However, when I run the Tray, and start the WPF window through code, the App.xaml is never called.

In App.xaml, a ResourceDictionary is defined:

<Application x:Class="MRS.Sender_Receiver.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Shell.xaml">
    <Application.Resources>
        <ResourceDictionary Source="Themes\Generic.xaml"/>
    </Application.Resources>
</Application>



This resource is not loaded when called from the Tray:

        private void settingsEvent_Click(object sender, EventArgs e)
        {
            gui = new MRS.Sender_Receiver.mainWindow(); // mainWindow() is located in Shell.xaml.
            gui.Show();
        }



Does anyone have an idea of how I can call a WPF application from another application, and have it load the ResourceDictionary when it is not using App.xaml? In other words, I need to set the dictionary either in Shell.xaml or in code-behind somewhere.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Set ResourceDictionary when loading WPF from a different project

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,262
  • Joined: 05-May 12

Re: Set ResourceDictionary when loading WPF from a different project

Posted 01 October 2012 - 03:16 PM

Have you considered dropping the WinForms tray app, and using a WPF tray app instead: http://www.codeproje.../WPF-NotifyIcon
Was This Post Helpful? 1
  • +
  • -

#3 Tim.Simon  Icon User is offline

  • New D.I.C Head

Reputation: 13
  • View blog
  • Posts: 26
  • Joined: 12-June 12

Re: Set ResourceDictionary when loading WPF from a different project

Posted 02 October 2012 - 08:26 AM

I finally figured this one out. Instead of instantiating the UI, the entire WPF application must be called to run. This will cause the App.xaml to load the dictionary, and other WPF forms can then access it. This is done with the following code:

        private void settingsEvent_Click(object sender, EventArgs e)
        {
            app.InitializeComponent();
            gui = new Sender_Receiver.mainWindow();
            app.Run(gui);
        }
        private static App app = new App();



This was discovered through experimentation, so i am sure it is not the best practice, but it works, and right now, that was what I needed.

Thank you, Skydiver, for your assistance with both of my posts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1