这是我的代码
我运行winform
应用程序我希望将Listbox
的索引绑定到在seprate class
和Thread
public Form1()
{
InitializeComponent();
var binding = new Binding("ScriptListBox", ScriptHandler.DomainScriptHanlderAgent, "ScriptCounter", false, DataSourceUpdateMode.OnPropertyChanged);
ScriptListBox.DataBindings.Add(binding);
}
public static class ScriptHandler
{
public static DomainLayer.DomainScriptHandler DomainScriptHanlderAgent = new DomainLayer.DomainScriptHandler();
}
这里我实现了属性更改
public class DomainScriptHandler : INotifyPropertyChanged
{
public static readonly object ScriptLocker = new object();
public event PropertyChangedEventHandler PropertyChanged;
private int scriptCounter;
private ISynchronizeInvoke invoker;
public Stack<string> ScriptCurrentTree = new Stack<string>();
/// <summary>
/// each move this will fire to form to move index step further
/// </summary>
public int ScriptCounter
{
get { return scriptCounter; }
set
{
scriptCounter = value;
OnPropertyChanged();
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null)
{
Action action = () => handler(this, new PropertyChangedEventArgs(propertyName));
invoker.Invoke(action, null);
}
}
但是当我运行它时,我在Cannot bind to the property 'ScriptListBox' on the target control.
class Form
ScriptListBox.DataBindings.Add(binding)
”例外
我在这里想念的是什么?