2

has anyone ever tried or felt the need to start their application in a stand alone exe and use WPF as just another DLL, rather than having the Main method within it?

The advantages I see are logical separation, and being able to set up a factory etc outside the WPF code, thus reducing assembly dependencies.

I have tried doing this and can get so far e.g. by setting the WPF project setting to 'class library', removing the startupuri from app.xaml and setting its build action to compile etc, and either calling app.run from the separate exe or having a method within the main window call this.

However, the resources (e.g. styles defined for buttons) in app.xaml appear not to have any effect when I do this. Converting the WPF project back to its default settings (startupuri etc) get the resources working again, but I'm not sure where the problem lies. Any ideas?

sturdytree
  • 849
  • 3
  • 12
  • 26
  • 1
    Did you think of doing it the other way around? Let the WPF be the exe, and separate your code out to a library? – R. Martinho Fernandes Apr 27 '11 at 14:09
  • Totally agree with @Martinho Fernandes. It is actually what I usually do: having in my WPF project all the application-related views & viewmodels, and keeping custom reusable views, converters and business objects in a separate library – Damascus Apr 27 '11 at 14:29
  • Martinho/Damascus, I have the usual separate layers (controllers, domain, repository etc) and see the view (WPF) layer as just another layer. Hence I prefer to have a separate exe that initialises and starts the whole application. Easiest option is of course to have your startup project be the WPF project, as that is how MS seems to want you to do things, but that's not the way I wish to do it. – sturdytree Apr 27 '11 at 17:40
  • I even put my application-specific views+viewmodels in a User Control Library, then just have a thin little WPF app that uses that library – default.kramer Apr 28 '11 at 15:32

1 Answers1

0

You can create Control libraries (Custom Control Libraries or User Control Libraries) to separate reusable controls from the application. But as its called they are Control Libraries. You can set Resources to UserControls, Pages, ... but not on Applications, cause they are not known in a Control library.

The generic XAML for your Controls should not be stored in the resources of the app.xaml, but in the Themes/Generic.xaml file.

User Control Library vs Custom Control library

Community
  • 1
  • 1
fixagon
  • 5,506
  • 22
  • 26
  • fantasticfix, thanks for your response, but it's not about reusable controls as such. I want to set default styles for the particular application (e.g. button width) and the only way I know of to do this for the whole application is to specify this in app.xaml, or have app.xaml reference another resources dictionary. However, calling app.run other than the 'standard' way seems to stop the resources working. – sturdytree Apr 27 '11 at 17:47