c#WindowsForms数据绑定不会更新所有字段
有一个windows窗体应用程序,其中有几个字段应通过数据绑定进行更新。 所有字段将包含在“此”部分中,所有字段将显示在所附标签中,但不显示在[BaustelleName]中 要使用的源是:c#WindowsForms数据绑定不会更新所有字段,c#,winforms,data-binding,C#,Winforms,Data Binding,有一个windows窗体应用程序,其中有几个字段应通过数据绑定进行更新。 所有字段将包含在“此”部分中,所有字段将显示在所附标签中,但不显示在[BaustelleName]中 要使用的源是: public string BaustelleName { get { return string.IsNullOrEmpty(this.sName) ? null : sName; } set { sName =
public string BaustelleName
{
get { return string.IsNullOrEmpty(this.sName) ? null : sName; }
set
{
sName = value;
InvokePropertyChanged(new PropertyChangedEventArgs("BaustelleName"));
}
}
public string BaustelleZusatz
{
get { return string.IsNullOrEmpty(this.sZusatz) ? null : sZusatz; }
set
{
sZusatz = value;
InvokePropertyChanged(new PropertyChangedEventArgs("BaustelleZusatz"));
}
}
。。。其他字段也一样。
我发现,[BaustelleName]的getter从未被调用,而所有其他的getter在每次调用[InvokePropertyChanged]时都被调用
可能有什么问题?您将绑定添加到错误的标签:您将其添加到lbl_ArdKunde而不是lbl_AdrBaustelle
//lbl_AdrBaustelle_Zl1.Text = adr.VornameName; ---------------------------------------
parent.lbl_AdrBaustelle_Zl1.DataBindings.Clear();
bnd = new Binding("Text", this, "BaustelleName");
parent.lbl_AdrKunde_Zl1.DataBindings.Add(bnd);
@你说得对;非常感谢,并为这个愚蠢的问题道歉。正如我们在德语中所说:“有时你看不到眼前的手”
public void InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChanged?.Invoke(this, e);
}
//lbl_AdrBaustelle_Zl1.Text = adr.VornameName; ---------------------------------------
parent.lbl_AdrBaustelle_Zl1.DataBindings.Clear();
bnd = new Binding("Text", this, "BaustelleName");
parent.lbl_AdrKunde_Zl1.DataBindings.Add(bnd);