[英]MethodInvoker in WPF?
Is there any in-built delegate like System.Windows.Forms.MethodInvoker
for WPF
?是否有像System.Windows.Forms.MethodInvoker
这样的内置委托WPF
?
I was porting some functionality from WinForms
to WPF
, for this I was not wising to import winforms reference, is there any corresponding delegate in WPF
?我正在将一些功能从WinForms
移植到WPF
,为此我不知道导入 winforms 参考, WPF
是否有相应的委托?
You can use just like this;你可以这样使用;
Dispatcher.BeginInvoke(new Action(delegate
{
// Do your work
}));
MethodInvoker is used in WPF also. MethodInvoker也用于 WPF。 And you can use it in Dispatcher.Invoke or Control.Invoke methods.您可以在 Dispatcher.Invoke 或 Control.Invoke 方法中使用它。 Also you can use Action delegate which has many overridings.您也可以使用具有许多覆盖的Action委托。 They both will be efficient.他们都将是高效的。
For example, you have button control btnLogin you can use it like this:例如,您有按钮控件 btnLogin,您可以像这样使用它:
In WPF:在 WPF 中:
btnLogin.Dispatcher.Invoke(new Action(delegate
{
// Running on the UI thread
btnLogin.Content = "TEST";
}));
In Winform:在 Winform 中:
btnLogin.Invoke((MethodInvoker)delegate {
// Running on the UI thread
btnLogin.Text = "TEST";
});
Cheers!干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.