2

What is the basic difference between the WPF custom control library and wpf class library.I want to understand the difference in terms of dll and architecture point of view .Because custom control is itself a class and WPF class library is also contains class.But custom control class is not working in wpf class library.

Gautam Kumar
  • 83
  • 1
  • 9
  • Can you add an example of one of your custom control that is not working? WPF ustom controls don't work like they do in Winforms – CarlosJ Apr 25 '14 at 12:02
  • 1
    http://stackoverflow.com/questions/807703/what-is-the-difference-between-a-user-control-library-and-a-custom-control-libra – CarlosJ Apr 25 '14 at 12:06
  • Does this answer your question? [Differences between WPF Custom Control Library and plain Class Library?](https://stackoverflow.com/questions/2089041/differences-between-wpf-custom-control-library-and-plain-class-library) – cdiggins Dec 10 '21 at 17:50

1 Answers1

9

You can think of WPF Custom Control Library as a simple Class Library with a few more configurations:

ThemeInfo assembly attribute:

[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                         //(used if a resource is not found in the page, 
                         // or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
                                  //(used if a resource is not found in the page, 
                                  // app, or any theme specific resource dictionaries)

)]

The above attribute specifies where to seek the default Styles/Templates for the control. You can get from the comments above what the ResourceDictionaryLocation.SourceAssembly does, the default location in SourceAssembly where the Resources are searched is the special path Themes/Generic.xaml which are created by default when you add a new WPF Custom Control Library.

You can add these manually and transform a Class Library into a WPF Custom Control Library.

Without the ThemeInfo attribute the default Styles/Templates are searched only in application resource dictionaries and if you don't have one you will get an error. Thats why CustomControls most commonly does not work with Class Library.

Novitchi S
  • 3,711
  • 1
  • 31
  • 44