user547064
user547064

Reputation: 217

Custom control Lib with multiple controls and generic.xaml

if i define two default styles for two different controls in one custom control lib i get errors...

is it possible to have two or more controls with a default generic.xaml in one lib?

Thanks

Upvotes: 2

Views: 2276

Answers (2)

Wonko the Sane
Wonko the Sane

Reputation: 10813

Yes.

Not only is it possible, it is the default behavior.

This is, of course, assuming that the two controls are in the same namespace.

You don't specify the error(s) that you are getting, so I can't offer much more detail.

Upvotes: 0

Pavlo Glazkov
Pavlo Glazkov

Reputation: 20746

Yes, it is possible. The recommended approach is to place styles for each control in its own resource dictionary and have one Generic.xaml file that will reference others.

So, for example, if you have two controls in your library: MyControl1 and MyControl2. Then you will have the following files in the Themes folder of your project:

  • generic.xaml
  • MyControl1.generic.xaml
  • MyControl2.generic.xaml

And your generic.xaml will look like this:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/MyControlLib;component/Themes/MyControl1.generic.xaml" />
        <ResourceDictionary Source="/MyControlLib;component/Themes/MyControl2.generic.xaml" />        
    </ResourceDictionary.MergedDictionaries>       


</ResourceDictionary>

Upvotes: 7

Related Questions