在 WPF UserControl 库中使用 MaterialDesignInXamlToolkit

Use MaterialDesignInXamlToolkit in a WPF UserControl library

我想使用 MaterialDesignInXamlToolkit 创建一个 wpf UserControl 库。

显然图书馆没有快速入门指南建议的 App.xaml 文件。我的印象是,我可以使用 Themes\Generic.xaml 文件加上 AssemblyInfo.cs 中的 ThemeInfo 属性,但这不起作用(显然这仅适用于 CustomControls)- 它无法解析资源.

有没有办法让这个在 wpf class 库中工作?

<Grid>
    <Button Style="{StaticResource MaterialDesignRaisedAccentButton}"
            Foreground="{StaticResource SecondaryHueLightBrush}"/>
</Grid>

安装 NuGet 包并在使用应用程序的 App.xaml 文件中引用资源字典,或者安装包并在库中的控件本身中引用相同的资源字典:

<UserControl x:Class="WpfControlLibrary1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfControlLibrary1"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Button Style="{StaticResource MaterialDesignRaisedAccentButton}"
            Content="Test"/>
    </Grid>
</UserControl>

确保在构建时将 MaterialDesignThemes.Wpf 和 MaterialDesignColors 程序集复制到应用程序的输出目录:

Dependent DLL is not getting copied to the build output folder in Visual Studio