读书人

WPF DependencyProperty 自定义依赖项

发布时间: 2012-01-13 22:43:29 作者: rapoo

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可以看看视频教程

读书人网 >.NET

热点推荐