具有多个控件和generic.xaml的自定义控件Lib

use*_*064 2 wpf controls

如果我在一个自定义控件lib中为两个不同的控件定义两个默认样式,我会收到错误...

是否可以在一个库中使用两个或多个具有默认generic.xaml的控件?

谢谢

Pav*_*kov 5

对的,这是可能的.建议的方法是将每个控件的样式放在自己的资源字典中,并使用一个将引用其他控件的Generic.xaml文件.

因此,例如,如果库中有两个控件:MyControl1和MyControl2.然后,您将在Themes项目的文件夹中包含以下文件:

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

你的generic.xaml将如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)