0

Let's start from the beggining. I have an app in wpf which uses my custom window style. I'm defining this custom style in app.xaml like below:

<Application x:Class="GeoLocations.Test.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="ThemedWindowStyle.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Nowadays there came a requirement that i need to build this application as dll and later on call it from Windows.Forms application. Obviously the app.xaml code is not being fired since this is not start up application anymore. Is there any way to load it ?

I tried to manually register this Dictionary in code behind but with no success. I also tried to change Build Action from "Page" to "Content" and "Do not copy" to "Copy if newer" but it is giving me different exception:

'Failed to create a 'Type' from the text 'local:ThemedWindow" with inner exception "{"Type reference cannot find type named '{clr-namespace:GeoLocations.Test}ThemedWindow'."} (this exception is beeing fired inside ResourceDictionary so it's loaded but why it can't find the type ?).

ThemedWindow is a type which inherits from Window and later on all my windows inherits from ThemedWindow instead of Window

I have no idea how to solve this issue. Anyone got some knowledge to help ?

Nazmul
  • 575
  • 3
  • 18
MajkeloDev
  • 1,661
  • 13
  • 30
  • Whether the `App.xaml` is loaded should be independent of how the application is started, semantically it's still part of the `App` class. – H.B. May 21 '15 at 19:17
  • @H.B. You don't understand - I compiled this as dll so now i want to call this like MyDll.MainWindow window = new MyDll.MainWindow(). There is no way to load it like beofre. – MajkeloDev May 22 '15 at 07:02
  • Then you are not simply building the application as dll but turning the application into a component library, which is a different thing... – H.B. May 22 '15 at 09:22
  • Maybe You're right - so can You give me some advice how to "simply build the application as dll" ? Some link maybe ? My goal is to open this application do something and in application which fired this one - retrieve some data. – MajkeloDev May 22 '15 at 09:25
  • Well, if you build it as application the only difference is that the built assembly is marked as executable with an entry point that runs the application. Theoretically you should be able to run the application manually as well (with all its features, including application-global resources). Here would be an example of running a WPP app in a simple console application: http://stackoverflow.com/a/8049984/546730 (You of course would need run your specific `App` subclass.) Also you can just still build the application as exe and then reference the exe directly, would maybe be easier to configure. – H.B. May 22 '15 at 09:31

1 Answers1

0

Ok, so i resolved this be adding my ResourceDictionary in code behind in my ThemedWindow Constructor. Like below:

   var rd = new ResourceDictionary();
   rd.Source = new Uri("pack://application:,,,/GeoLocations Screens;component/ThemedWindowStyle.xaml");
   Resources.MergedDictionaries.Add(rd);
MajkeloDev
  • 1,661
  • 13
  • 30