我使用类库(WPF 用户控件库)来托管项目解决方案中的其他(C#-)应用程序使用的一些用户控件。我希望这些控件使用位于类库顶部范围的 XAML ControlTemplates。ControlTemplates 不必在类库之外使用。
这里是一个模板声明:
<ControlTemplate TargetType="{x:Type Button}" x:Key="TemplateImageButtonSmall">
<Grid>
<Image Name="img" Source="/PSCommonUI;component/Images/Buttons/ButtonMinus_normal.png"/>
</Grid>
</ControlTemplate>
然后我在类库中有一个用户控件,包含:
<Button Height="57" Margin="10,0,6,5" Name="button3" Template="{StaticResource TemplateImageButtonSmall}" Width="82">
在应用程序中,我可以使用 App.xaml 文件来定义模板。但是,在类库中我没有这个选项。
我在网上搜索并找到了一些答案,包括使用 generic.xaml 文件、ComponentResourceKey、合并资源文件和其他我觉得过于复杂的东西。
我还读到主题定义(一般的资源)不应该驻留在类库中。
但是,如果我只需要在此类库中为托管控件提供一些主题,那么最佳实践如何?
提前致谢,
朱利安