0
我有下面的代碼打開一個對話框,向用戶指示應用程序正在另一個線程中處理,然後一旦它接收到LoadCompletedEvent就會關閉窗口。但是,我總是得到以下錯誤,並不確定它指的是什麼。WPF System.Reflection.TargetParameterCountException參數計數不匹配
An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in PresentationFramework.dll
Additional information: Parameter count mismatch.
這就是如何創建線程。
Thread thread = new Thread(() =>
{
MetroProgressWindow metroProgressWindow = new MetroProgressWindow(this);
metroProgressWindow.ShowDialog();
});
thread.SetApartmentState(ApartmentState.STA);
//thread.IsBackground = true;
thread.Name = "omega-thread";
thread.Start();
// create window, do loading, business logic, etc
// throw load completed event
LoadCompletedEvent(this, EventArgs.Empty);
Visibility = Visibility.Hidden; // hide MainWindow
renderWindow.ShowDialog(); // show the RenderWindow as a modal dialog NOTE: this is thread blocking
然後在其他窗口中的代碼看起來像這樣。
public partial class MetroProgressWindow : MetroWindow
{
public MetroProgressWindow(IOmegaWindow window)
{
InitializeComponent();
window.LoadCompletedEvent += delegate
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new Action(() => { this.Close(); }),
null);
};
}
}
我假設,你正在使用MahApps? – lokusking
我正在使用MahApps。新對象[2]不起作用,但是當進行進一步調試時,它在metroProgressWindow.ShowDialog()上失敗。其中不包含任何參數 – jkratz55
ShowDialog不接受任何參數的事實完全不相關:它激活了窗口的邏輯,問題在於Action沒有參數。 –