![](/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.