我有一個數據網格。我想添加列作爲事件的結果。 所以我做OnEvent datagrid列添加失敗
for (int iii = 1; iii <= 4; ++iii)
{
var dtgColumn = new DataGridTextColumn();
dtgColumn.Header = "AAA"
Dispatcher.Invoke((Action)(() => { dtgResults.Columns.Add(dtgColumn); }));
}
但是,儘管使用一個調度程序我得到這個錯誤:
The calling thread cannot access this object because a different thread owns it.
感謝您的幫助 帕特里克 }
嘗試使用Application.Current.Dispatcher。有關更多詳細信息,請參閱此處:http://stackoverflow.com/questions/10448987/dispatcher-currentdispatcher-vs-application-current-dispatcher –
唉,不像以前那樣工作 – Patrick
dtgResults定義在哪裏,它在哪裏實例化? (哪個線程?) –