首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TemplateBinding的WPF问题

TemplateBinding的WPF问题
EN

Stack Overflow用户
提问于 2011-10-06 02:16:10
回答 1查看 159关注 0票数 0

我正在使用VS2008。我上过这门课

代码语言:javascript
复制
[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的文件)中

代码语言:javascript
复制
<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。如果我双击错误消息,即使在VS2008中打开了Generic.xaml,我也会得到一个不同的Generic.XAML的不同选项卡,只是内容是相同的,如果我复制每个选项卡的完整路径,我会看到:

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

虽然有点尴尬,但它们是相同的路径。

有什么线索吗?

EN

回答 1

Stack Overflow用户

发布于 2011-10-06 02:28:46

你已经把你的generic.xaml设为本地拷贝了吗?另外,不要忘记在文件的属性上设置选项:"Copy to output directory“为"Copy always",因为generic.xaml不是用来编译的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7665773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档