学习WPF
Kevin仿Clock的范例想用data binding,但是一直用不成,我也不懂,于是一起研究了一下,才发现原来binding之前需要设置DataContext,代码如下:
public Window1()
{
InitializeComponent();
textBox1.DataContext = this;
}
public static DependencyProperty dp;
static Window1()
{
dp = DependencyProperty.Register("ddd", typeof(String), typeof(Window1),new PropertyMetadata("dsdsds"));
}
public string ddd
{
get
{
return (string)GetValue(dp);
}
set
{
SetValue(dp,value);
}
}
{
InitializeComponent();
textBox1.DataContext = this;
}
public static DependencyProperty dp;
static Window1()
{
dp = DependencyProperty.Register("ddd", typeof(String), typeof(Window1),new PropertyMetadata("dsdsds"));
}
public string ddd
{
get
{
return (string)GetValue(dp);
}
set
{
SetValue(dp,value);
}
}
这样在xaml里面属性绑定才有用。。
