在单独的dll WPF中设置资源

use*_*195 2 c# wpf resourcedictionary .net-assembly

我想在一个独立的dll中包含一组样式,可以从许多不同的WOF类中引用它们来定义常见样式.

我已经创建了独立的dll并尝试引用它但是遇到了问题.

这是独立dll的代码:

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

        <Style x:Key="myStyle" TargetType="Button">
            <Setter Property="Background" Value="Orange" />
            <Setter Property="FontStyle" Value="Italic" />
            <Setter Property="Padding" Value="8,4" />
            <Setter Property="Margin" Value="4" />
        </Style>

    <!-- store here your styles -->
</ResourceDictionary> 
Run Code Online (Sandbox Code Playgroud)

这是我试图引用它的地方:

<src:GX3ClientPlugin.Resources>
    <ResourceDictionary Source="pack://application:,,,/GX3StyleResources.dll;component/GX3StyleResources.xaml" />
</src:GX3ClientPlugin.Resources>
Run Code Online (Sandbox Code Playgroud)

运行时,我得到以下异常:

无法加载文件或程序集"GX3StyleResources.dll,Culture = neutral"或其依赖项之一.该系统找不到指定的文件.

有任何想法吗?

小智 5

我在一些项目中也这样做,我所做的是将dll作为参考添加到我的项目中,然后我使用包Uri但我没有指定扩展名.dll.我只是使用程序集名称(通常没有.dll)

Source="pack://application:,,,/GX3StyleResources;component/GX3StyleResources.xaml"
Run Code Online (Sandbox Code Playgroud)