WPF 类库中的 ResourceDictionary

Kro*_*owi 2 c# wpf xaml class-library resourcedictionary

我有Class Library以下代码位。

以下是我UserControlResource

<UserControl.Resources>
    <ResourceDictionary Source="pack://application:,,,/Mine.Controls;component/Templates.xaml" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

下面是我的ResourceDictionary名为Templates.xaml 的文件:

构建操作:资源

复制到...:不要复制

自定义工具:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ControlTemplate x:Key="MyButton"
                     TargetType="Button">
        <Border x:Name="buttonBorderOuter"
                BorderBrush="#DBDBDB"
                BorderThickness="1"
                Background="#00ECECEC"
                CornerRadius="5" />
    </ControlTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

然后我得到错误

异常:查找资源字典“pack://application:,,,/Mine.Controls;component/Templates.xaml”时发生错误。

我究竟做错了什么?

Moe*_*bai 5

尝试将构建操作更改为Templates.xamlto Page