1. 程式人生 > >C#の----Func,Action,predicate在WPF中的應用

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

邏輯 clas color for edi sender fun document pub

首先介紹下,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"; })); } } }

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