模板绑定的WPF问题

模板绑定的WPF问题,wpf,visual-studio-2008,Wpf,Visual Studio 2008,我正在使用VS2008。我有这门课 [System.Windows.Markup.ContentProperty("Child")] public class CaptionedBox : Control { static CaptionedBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CaptionedBox), new FrameworkPropertyMetadata

我正在使用VS2008。我有这门课

[System.Windows.Markup.ContentProperty("Child")]
public class CaptionedBox : Control
{
    static CaptionedBox()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(CaptionedBox), 
            new FrameworkPropertyMetadata(typeof(CaptionedBox)));
    }

    public static readonly DependencyProperty ShadeVisibilityProperty = 
        DependencyProperty.Register(
        "ShadeVisibility", typeof(Visibility), typeof(CaptionedBox), new 
         PropertyMetadata(Visibility.Hidden));
}
这段代码位于名为Generic.xaml的文件中的ResourceDictionary中

<ControlTemplate TargetType="{x:Type wft:CaptionedBox}">
    <Grid>
        ...
        <Rectangle Fill="#44000000" Visibility="{TemplateBinding ShadeVisibility}"/>
    </Grid>
</ControlTemplate>
没有错误,没有问题,我到处都用这个CaptionedBox

我在同一个项目中有另一个XAML页面,它引用了这个ResourceDictionary,Source=../Themes/Generic.XAML。当我打开该页面时,它显示资源字典XAML文件有错误,无法加载。此时它引用的是Generic.XAML。如果我双击错误消息,即使在VS 2008中打开了Generic.XAML,我也会看到一个不同的选项卡,它看起来像是不同的Generic.XAML,只是内容相同,如果我复制每个选项卡的完整路径,我会看到:

C:\Source\LyonsForge\root\pumpservice\branchs\PSRT\u 1\u 0\u 2\Code\Bench\Controls\Wizard..\Themes\Generic.xaml C:\Source\LyonsForge\root\pumpservice\branchs\PSRT\u 1\u 0\u 2\Code\Bench\Controls\Themes\Generic.xaml

<ControlTemplate TargetType="{x:Type wft:CaptionedBox}">
    <Grid>
        ...
        <Rectangle Fill="#44000000" Visibility="{TemplateBinding ShadeVisibility}"/>
    </Grid>
</ControlTemplate>
虽然有点尴尬,但都是同一条路


有什么线索吗?

您是否已经将generic.xaml设置为本地副本?另外,不要忘记在file属性上设置选项:Copy to output directory to Copy always,因为generic.xaml不是要编译的。

我在研究时做的其他事情:删除所有obj和bin文件夹,清理并重建整个项目,在整个硬盘上搜索Generic.Xaml的其他实例…重新启动:复制本地目录和复制到输出目录之间有什么区别?此应用已运行两年,复制到输出目录=不复制。但我还是试着把它改成“总是复制”。我也犯了同样的错误。