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