Is there any in-built delegate like System.Windows.Forms.MethodInvoker
for 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
?
You can use just like this;
Dispatcher.BeginInvoke(new Action(delegate
{
// Do your work
}));
MethodInvoker is used in WPF also. And you can use it in Dispatcher.Invoke or Control.Invoke methods. Also you can use Action delegate which has many overridings. They both will be efficient.
For example, you have button control btnLogin you can use it like this:
In WPF:
btnLogin.Dispatcher.Invoke(new Action(delegate
{
// Running on the UI thread
btnLogin.Content = "TEST";
}));
In Winform:
btnLogin.Invoke((MethodInvoker)delegate {
// Running on the UI thread
btnLogin.Text = "TEST";
});
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With