所以我需要使用WinForms,因为我的应用程序将在单声道上运行。
我有一个名为Logic的类,我在该类中有一个类型为Part的属性,我有一个部件号。部件更改时,我想用部件号更新UI。我所能做的就是绑定Part而不是Part的属性。
public class Logic : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public Part Part { get; private set; }
public void ChangeSequence(int fixtureId)
{
Part = new Part() {partNumber = "aetrasdsd"};
this.OnPropertyChanged(nameof(Vitrek_Library.Part));
}
}
public partial class Main : Form
{
public Main()
{
InitializeComponent();
Program.Logic.Initialize(omronEthernetFINSCom1);
Program.Logic.DataSubFixtureId.DataChanged += DataSubFixtureID_DataChanged;
Program.Logic.SequenceDone += Logic_SequenceDone;
Binding b = new Binding("Text", Program.Logic, nameof(Vitrek_Library.Part) + ".partNumber", true)
{
//FormatString = $"Part Number: {0}"
};
lblPartNumber.DataBindings.Add(b);
}
}
答案 0 :(得分:0)
将绑定路径设置为Part.partNumber的问题在于绑定时Part是null。