C#の----Func,Action,predicate在WPF中的应用

时间:2024-08-25 16:35:32

首先介绍下,winform中可以用this.invoke来实现;wpf中要使用调度器Control.Despite.invoke;

(Action)(()=>

{

})和

new Action (()=>
{
 button1.Content = "Action";
 })是等价的

using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace WpfApplication1_weituoTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void button1_Click(object sender, RoutedEventArgs e)
{
//button1.Dispatcher.BeginInvoke((Action)(() =>
//{
// button1.Content = "Action";
//})); button1.Dispatcher.BeginInvoke(new Action (()=>
{
button1.Content = "Action";
})); }
}
}