![](/img/trans.png)
[英]MethodInvoker + lambda + arguments + CrossThread Operation
[英]MethodInvoker in WPF?
是否有像System.Windows.Forms.MethodInvoker
這樣的內置委托WPF
?
我正在將一些功能從WinForms
移植到WPF
,為此我不知道導入 winforms 參考, WPF
是否有相應的委托?
你可以這樣使用;
Dispatcher.BeginInvoke(new Action(delegate
{
// Do your work
}));
MethodInvoker也用於 WPF。 您可以在 Dispatcher.Invoke 或 Control.Invoke 方法中使用它。 您也可以使用具有許多覆蓋的Action委托。 他們都將是高效的。
例如,您有按鈕控件 btnLogin,您可以像這樣使用它:
在 WPF 中:
btnLogin.Dispatcher.Invoke(new Action(delegate
{
// Running on the UI thread
btnLogin.Content = "TEST";
}));
在 Winform 中:
btnLogin.Invoke((MethodInvoker)delegate {
// Running on the UI thread
btnLogin.Text = "TEST";
});
干杯!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.