2013-04-24 37 views
4

WPF是否有像System.Windows.Forms.MethodInvoker这样的内置代表?WPF中的MethodInvoker?

我正在将一些功能从WinForms移植到WPF,为此我不想导入winforms参考,是否有任何相应的代表在WPF

回答

5

MethodInvoker也用在WPF中。您可以在Dispatcher.Invoke或Control.Invoke方法中使用它。你也可以使用Action代表,它有很多重写。他们都将是有效的。

+2

'MethodInvoker也存在于WPF中,什么名字空间? – Brij 2013-04-24 10:11:02

+0

@Brij好吧,也许我的回答有点不清楚。我的意思是你可以在System.Windows.Forms.MethodInvoker中使用它,而WPF对象可以使用并接受它。但是如果你不希望它引用System.Windows.Forms,你应该使用Action类 – Alex 2013-04-24 10:15:54

+0

Action委托似乎更可能被使用。谢谢@voo – Brij 2013-04-26 09:35:22

7

你可以像这样使用;

Dispatcher.BeginInvoke(new Action(delegate 
    { 
    // Do your work 
    }));