zoukankan      html  css  js  c++  java
  • 依赖属性和绑定的问题。“属性"ImgSource"不是DependencyProperty”

    img
    属性"ImgSource"不是DependencyProperty。若要在标记中使用,目标类型必须通过可访问的实例属性"ImgSource"来公开非附加属性。对于附加属性,声明的类型必须提供静态的"GetImgSource"和"SetImgSource"方法。!

    参考方法

    MSDN上网友的解答
    分析原因:Image不是继承自FrameworkElement的,templatebinding不好用。

    解决办法

    使用Binding
    示例:

            <Style x:Key="xButton" TargetType="local:MyButton">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="local:MyButton">
                            <StackPanel Orientation="Horizontal" Width="250">
                                <Image Source="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ImgSource}" Width="50" Height="25"/>
                                <ContentPresenter x:Name="contentPresenter"  Content="{TemplateBinding Content}"
                                                  Foreground="White" VerticalAlignment="Center"/>
                            </StackPanel>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
  • 相关阅读:
    局域网中电脑之间无法ping通问题
    Python 字典dict操作定义
    set集合
    Python 元组遍历排序操作方法
    Python List 列表list()方法
    set函数&操作
    dict函数
    文件操作
    list函数
    字符串格式化format使用
  • 原文地址:https://www.cnblogs.com/woodytian/p/4861726.html
Copyright © 2011-2022 走看看