我定義爲這個C#PictureBox.Image的DataBind到物體圖像物業
public class Employee : INotifyPropertyChanged
{
private Image photo;
public Image Photo
{
get { return photo; }
set { photo = value; InvokePropertyChanged(new PropertyChangedEventArgs("Photo")); }
}
#region Implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, e);
}
#endregion
}
類Employee
這是我的用法:我已經命名爲pbPhoto
和圖片一個PictureBox
控制有默認值從我的Resources.Blank
,該屬性是事件內的Employee.Photo
屬性的數據綁定。
Employee employee = new Employee();
this.pbPhoto.DataBindings.Add("Image", employee, "Photo");
但它似乎不工作,我得到了這個錯誤信息。
無法將值格式化爲所需的類型。
第二個參數應該包含一個對象,而不是一個類型 – Mono
請檢查修訂後的問題。 –
我沒有看到你實際設置照片屬性的位置。我想你不能設置一個綁定到一個返回null的屬性 – Mono