当前位置: 代码迷 >> .NET新技术 >> WPF DependencyProperty 自定义依赖项属性的有关问题
  详细解决方案

WPF DependencyProperty 自定义依赖项属性的有关问题

热度:408   发布时间:2016-04-25 01:55:21.0
WPF DependencyProperty 自定义依赖项属性的问题
我参考http://msdn.microsoft.com/zh-cn/partners/system.windows.dependencyproperty(VS.95).aspx
定义名为LabelText的用户控件 自定义属性名为LabelName
C# code
    public partial class LabelText : UserControl    {        public static readonly DependencyProperty LabelTextProperty =            DependencyProperty.Register(            "LabelName", typeof(String),            typeof(LabelText), null            );        public String LabelName        {            get { return (String)GetValue(LabelTextProperty); }            set { SetValue(LabelTextProperty, value); }        }        public LabelText()        {            InitializeComponent();//this.LabelName始终为NULL        }    }

我是使用如下方式引用该控件并初始值的
<....
 xmlns:common="clr-namespace:CommonControl"
>
<common:LabelText LabelName="道具名称"></common:LabelText>

但在我的LabelText类的构造中无法得到LabelName为“道具名称” 它始终为NULL.
为何??????????????

------解决方案--------------------
http://www.langsin.com/index.html?ID=30可以看看视频教程