隐式主题错误:在类型'System.Windows.Controls.Control'中找不到属性'内容' [英] Implicit theme error:The property 'Content' was not found in type 'System.Windows.Controls.Control'

查看:34
本文介绍了隐式主题错误:在类型'System.Windows.Controls.Control'中找不到属性'内容'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试将我们的大型项目升级到SL4时出错。 原创主题不是我写的,我的主题知识也不是很好。 在我的演示应用程序中,我有一个Label和一个LabelHeader(这是我创建的,只是Label with DefaultStyleKey=typeof(LabelHeader)的派生类;
我正在设置LabelHeader的样式,如下所示:

 <Style TargetType="themeControls:LabelHeader">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <DataInput:Label 
                    FontSize="{TemplateBinding FontSize}" 
                    FontFamily="{TemplateBinding FontFamily}" 
                    Foreground="{TemplateBinding Foreground}" 
                    Content="{TemplateBinding  Content}"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="FontFamily" Value="Tahoma"/>
    <Setter Property="FontSize" Value="20"/>
    <Setter Property="Foreground" Value="Red"/>
</Style>

这在SL3中有效,但在SL4中我得到:

错误:Silverlight应用程序中未处理的错误 编码:2500
类别:ParserError
消息:在类型"System.Windows.Controls.Control"中找不到属性"Content"。
文件:
行:9
职位:168

如果我更改此设置: 内容="{TemplateBinding Content}" 至 Content="XXX" 这样就没有错误了,但是,当然,我的标签中有XXX,而不是我在页面上用XAML设置的内容

您有什么想法可以让它正常工作吗?

演示项目点击此处:

http://walkersretreat.co.nz/files/ThemeIssue.zip

(很抱歉转发,我目前在这里没有答案:http://forums.silverlight.net/forums/p/183380/415930.aspx#415930)

编辑提供的答案看起来会起作用。此处已针对此问题打开问题: https://connect.microsoft.com/VisualStudio/feedback/details/561183

如果您认为这很重要,请投票!

推荐答案

由于Wolf Schmidt(微软)在www.silverlight.net论坛上的帖子,该问题已按设计确定、解释并有可能得到解决。根据他的说法,Silverlight4现在将以更严格的方式考虑Silverlight3关于控件模板的准动态行为,这会导致Silverlight4在控件模板的TargetType属性不存在时出错。需要注意的是,当控制模板的TargetType的属性不存在时,Silverlight4将以更严格的方式考虑Silverlight3关于控件模板的准动态行为,这会导致Silverlight4中出现错误。需要注意的是,当控制模板的TargetType的属性不存在时,

解决此问题的方法是为ControlTemplate指定一个TargetType,以便模板绑定中使用的属性将被解析。

下面是具有为ControlTemplate指定的TargetType的更新样式:

<Style x:Key="LabelHeader" TargetType="controls:Label">
    <Setter Property="Margin" Value="0" />
    <Setter Property="Opacity" Value=".6" />
    <Setter Property="VerticalAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="controls:Label">
                <Border BorderBrush="#CCCCCCCC" BorderThickness=".5" Background="#CCEFEFEF">
                    <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="2" Content="{TemplateBinding Content}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

但是,如果IDE/IntelliSense可以验证TemplateBinding中指定的属性是否确实存在于ControlTemplate的默认/指定的TargetType上,则对开发人员非常有用。

来源: -我们关于Silverlight.NET的论坛讨论:(没有足够的声誉发布>1个超链接) -我的MS连接问题:https://connect.microsoft.com/VisualStudio/feedback/details/561183

这篇关于隐式主题错误:在类型&#39;System.Windows.Controls.Control&#39;中找不到属性&#39;内容&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆