无法绑定到目标控件异常c#上的属性

时间:2014-07-30 09:28:58

标签: c# data-binding

这是我的代码 我运行winform应用程序我希望将Listbox的索引绑定到在seprate classThread

中运行的索引
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)”例外

我在这里想念的是什么?

0 个答案:

没有答案