【发布时间】:2009-10-27 23:22:24
【问题描述】:
有人知道吗?
上周我一直在尝试这个,但没有运气。
现在我可以看到一次可以成功绑定到按钮的 Text 属性,但不能绑定到它的 ImageKey 属性:
myButton.Text = "new text"; // really changes the bound data
myButton.ImageKey = "new text"; // does NOT change the bound data
我用:
myButton.DataBindings.Add ( new Binding ( "ImageKey", this.MyData, "Name", true, DataSourceUpdateMode.OnPropertyChanged ) );
为什么?是什么使绑定滴答/工作?我就是不明白。
编辑:
好的,所以我为自己的派生控件定义了这些:
public event EventHandler ImageKeyChanged;
protected virtual void OnImageKeyChanged ( EventArgs e )
{
if ( ImageKeyChanged!= null )
{
ImageKeyChanged ( this, e );
}
}
[Bindable ( true )]
public new string ImageKey
{
get
{
return base.ImageKey;
}
set
{
base.ImageKey = value;
this.OnImageKeyChanged ( EventArgs.Empty );
}
}
还是不行。网上有没有教程之类的,可以说明这一点。它只是对我不起作用。
【问题讨论】:
标签: c# .net winforms data-binding