【问题标题】:WPF Issue with TemplateBinding模板绑定的 WPF 问题
【发布时间】:2011-10-05 18:16:09
【问题描述】:

我正在使用 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));
}

此代码在 ResourceDictionary 中(在名为 Generic.xaml 的文件中)

<ControlTemplate TargetType="{x:Type wft:CaptionedBox}">
    <Grid>
        ...
        <Rectangle Fill="#44000000" Visibility="{TemplateBinding ShadeVisibility}"/>
    </Grid>
</ControlTemplate>

没有错误,没有问题,我到处使用这个 CaptionedBox。

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

C:\Source\LyonsForge\root\PumpServicing\branches\PSRT_1_0_2\Code\Bench\Controls\Wizard..\Themes\Generic.xaml C:\Source\LyonsForge\root\PumpServicing\branches\PSRT_1_0_2\Code\Bench\Controls\Themes\Generic.xaml

虽然有点尴尬,但都是同一条路。

有什么线索吗?

【问题讨论】:

  • 我在研究时所做的其他事情:删除了所有 obj 和 bin 文件夹,清理并重建了整个项目,在整个硬盘驱动器中搜索了 Generic.Xaml 的其他实例......重新启动:)跨度>

标签: wpf visual-studio-2008


【解决方案1】:

您是否已经将您的 generic.xaml 复制到本地?另外不要忘记将文件属性上的选项:“复制到输出目录”设置为“始终复制”,因为 generic.xaml 并不意味着要编译。

【讨论】:

  • “复制本地”和“复制到输出目录”有什么区别?这个应用程序已经运行了两年,复制到输出目录 = 不要复制。但是我尝试将其更改为始终复制。遇到同样的错误。
猜你喜欢
  • 2011-02-25
  • 2012-12-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-09
  • 1970-01-01
相关资源
最近更新 更多