我想显示当前在标签中构建的对象的名称(Windows窗体)
我的标签没有实时刷新。当我在每次迭代后放置一个DialogBox或其他东西时,标签会获得良好的价值并且更新得很好,但是当我让我的代码运行而没有"中断"时,标签似乎有bug并且他的值永远不会改变...
我对进度条有相同类型的代码,一切运行良好。
ModelBuilder.cs
public event PropertyChangedEventHandler PropertyChanged;
private Substation currentSubstation;
public Substation CurrentSubstation
{
get
{
return this.currentSubstation;
}
set
{
if (value != this.currentSubstation)
{
this.currentSubstation = value;
NotifyPropertyChanged();
}
}
}
private void NotifyPropertyChanged(String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public void Build()
{
foreach (string substationUri in substationsUri)
{
Substation substation = new Substation(new Uri(substationUri));
this.CurrentSubstation = substation;
/* code */
}
}
View.cs
private void StartImportation_Click(object sender, EventArgs e)
{
this.model = new ModelBuilder(....);
this.myLabel.DataBindings.Add(new Binding("Text", this.model, "CurrentSubstation.name"));
this.model.Build();
}