那啥,是从这里整理出来的,感谢Rising_Sun,整理的过于简单,看不明白的戳这里

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
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 Delegate委托
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
delegate string SayMessage(string msg);
static string SayHello(string Name)
{
return string.Format("Hello {0}", Name);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
SayMessage say = new SayMessage(SayHello);
textBlock1.Text = say("委托");
} private void button2_Click(object sender, RoutedEventArgs e)
{
SayMessage say = delegate(string Name)
{
return string.Format("Hello {0}", Name);
};
textBlock2.Text = say("匿名方法");
} private void button3_Click(object sender, RoutedEventArgs e)
{
SayMessage say = (Name) =>
{
return string.Format("Hello {0}", Name);
};
textBlock3.Text = say("Lambda");
}
private void button4_Click(object sender, RoutedEventArgs e)
{
Func<string, string> say1 = delegate(string Name)
{
return string.Format("Hello {0}", Name);
};
//和Lambda 结合
Func<string, string> say2 = (Name) =>
{
return string.Format("Hello {0}", Name);
};
textBlock4.Text = say1("Func 委托") + say2("Func+Lambda 委托");
}
private void button5_Click(object sender, RoutedEventArgs e)
{
Action<string> say1 = delegate(string Name)
{
textBlock5.Text = (string.Format("Hello {0}", Name));
};
//和Lambda 结合
Action<string> say2 = (Name) =>
{
textBlock5.Text += (string.Format("Hello {0}", Name));
};
say1("Action 委托");
say2("Action+Lambda 委托");
}
}
}

下面那啥,不堪入目!没人看到没人看到没人看到。。。。。。

<Window x:Class="Delegate委托.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Grid>
<Button Content="Button" Height="" HorizontalAlignment="Left" Margin="34,12,0,0" Name="button1" VerticalAlignment="Top" Width="" Click="button1_Click" />
<TextBlock Height="" HorizontalAlignment="Left" Margin="166,12,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width=""/>
<Button Content="Button" Height="" HorizontalAlignment="Left" Margin="34,58,0,0" Name="button2" VerticalAlignment="Top" Width="" Click="button2_Click" />
<TextBlock Height="" HorizontalAlignment="Left" Margin="165,58,0,0" Name="textBlock2" Text="TextBlock" VerticalAlignment="Top" Width="" />
<Button Content="Button" Height="" HorizontalAlignment="Left" Margin="34,108,0,0" Name="button3" VerticalAlignment="Top" Width="" Click="button3_Click" />
<TextBlock Height="" HorizontalAlignment="Left" Margin="165,108,0,0" Name="textBlock3" Text="TextBlock" VerticalAlignment="Top" Width="" TextWrapping="Wrap"/>
<Button Content="Button" Height="" HorizontalAlignment="Left" Margin="34,158,0,0" Name="button4" VerticalAlignment="Top" Width="" Click="button4_Click" />
<TextBlock Height="" HorizontalAlignment="Left" Margin="165,158,0,0" Name="textBlock4" Text="TextBlock" VerticalAlignment="Top" Width="" TextWrapping="Wrap" />
<Button Content="Button" Height="" HorizontalAlignment="Left" Margin="34,208,0,0" Name="button5" VerticalAlignment="Top" Width="" Click="button5_Click" />
<TextBlock Height="" HorizontalAlignment="Left" Margin="165,208,0,0" Name="textBlock5" Text="TextBlock" VerticalAlignment="Top" Width="" TextWrapping="Wrap"/> </Grid>
</Window>

咳咳,反正是自己看的

WPF Delegate委托整理的更多相关文章

  1. 快速理解C#高级概念(一) Delegate委托

    做.NET开发很久,最近重新温习<C#高级编程>一书.发现很多曾经似懂非懂的问题,其实也是能够慢慢钻研慢慢理解的. 所以,打算开写<C#高级编程系列>博文.其中会借鉴<C ...

  2. 关于js模拟c#的Delegate(委托)实现

    这是我的第一篇博文,想来讲一讲js的函数.我的标题是js模拟c#的Delegate. 一.什么是Delegate(委托) 在jquery中有delegate函数,作用是将某个dom元素的标签的事件委托 ...

  3. (转)WPF学习资源整理

    由于笔者正在学习WPF,所以整理出网络中部分WPF的学习资源,希望对同样在学习WPF的朋友们有所帮助. 首推刘铁猛的<深入浅出WPF>系列博文 1.深入浅出WPF(1)——什么是WPFht ...

  4. WPF学习资源整理

    WPF(WindowsPresentation Foundation)是微软推出的基于Windows Vista的用户界面框架,属于.NET Framework 3.0的一部分.它提供了统一的编程模型 ...

  5. 使用 EPPlus 封装的 excel 表格导入功能 (二) delegate 委托 --永远滴神

    使用 EPPlus 封装的 excel 表格导入功能 (二) delegate 委托 --永远滴神 前言 接上一篇 使用 EPPlus 封装的 excel 表格导入功能 (一) 前一篇的是大概能用但是 ...

  6. 【UE4 C++ 基础知识】<8> Delegate 委托

    概念 定义 UE4中的delegate(委托)常用于解耦不同对象之间的关联:委托的触发者不与监听者有直接关联,两者通过委托对象间接地建立联系. 监听者通过将响应函数绑定到委托上,使得委托触发时立即收到 ...

  7. C# WPF 使用委托修改UI控件

    近段时间在自学WPF,是一个完全不懂WPF的菜鸟,对于在线程中修改UI控件使用委托做一个记录,给自已以后查询也给需要的参考: 界面只放一个RichTextBox,在窗体启动时开起两个线程,调用两个函数 ...

  8. C# WPF 通过委托实现多窗口间的传值

    在使用WPF开发的时候就不免会遇到需要两个窗口间进行传值操作,当然多窗口间传值的方法有很多种,本文介绍的是使用委托实现多窗口间的传值. 在上代码之前呢,先简单介绍一下什么是C#中的委托(如果只想了解如 ...

  9. C#中的委托 Delegate(委托 也叫代表,代表一类方法)

    1. 委托类似与 C或C++中的函数指针,但委托是 面向对象的,并且是类型安全的 详情可查看官方文档:https://msdn.microsoft.com/en-us/library/ms173172 ...

随机推荐

  1. Lucene.Net 2.3.1开发介绍 —— 二、分词(三)

    原文:Lucene.Net 2.3.1开发介绍 -- 二.分词(三) 1.3 分词器结构 1.3.1 分词器整体结构 从1.2节的分析,终于做到了管中窥豹,现在在Lucene.Net项目中添加一个类关 ...

  2. 【Demo 0004】Java基础-类封装性

    本章学习要点:       1.  Java封装特性;       2.  掌握类的定义:       3.  掌握类的调用方法; 一.封装特性        Java 纯面向对象语言,面向对象语言遵 ...

  3. 链栈之C++实现

    链栈是借用单链表实现的栈.其不同于顺序栈之处在于: 1.链栈的空间是程序运行期间根据需要动态分配的,机器内存是它的上限.而顺序栈则是 静态分配内存的. 2.链栈动态分配内存的特性使得它一般无需考虑栈溢 ...

  4. ASP.NET 常用内置对象详解-----Response

    利用提供的内置对象,可以实现页面之间的数据传递及实现一些特定的功能,如:缓冲输出,页面重定向等等. Response :响应,反应 Request:请求 Server:服务器 Application: ...

  5. Java中替代C# ref/out 关键字方案:

    刚学习Java不久,今天遇到一个问题,需要在方法中修改传入的对象的值,确切的说是需要使用一个方法,创建一个对象,并把其引用返回,熟悉C#的我的第一反应就是C#中的ref/out关键字,结果发现Java ...

  6. VMware vSphere服务器虚拟化实验十五 vCenter vShield Manager

    VMware vSphere服务器虚拟化实验十五 vCenter vShield Manager VMware  vShield Manager是专为 VMware vCenter Server 集成 ...

  7. WinMM.dll 函数汇总

    #include "MMSystem.h" auxGetDevCaps                  查询指定的辅助输出设备以确定其性能 auxGetNumDevs       ...

  8. ubuntu install mysql server method

         recently try to install mysql in my computer so that  I can practise some sql statement on seve ...

  9. Linux共享wifi给Android手机

    亲測可行,測试系统:Deepin2014,Ubuntu也一样.步骤很easy. 1.卸载hostapd,sudo apt-get remove hostapd(假设原来装过的话卸载,由于某些版本号不支 ...

  10. 每日一小练——高速Fibonacci数算法

    上得厅堂,下得厨房,写得代码,翻得围墙,欢迎来到睿不可挡的每日一小练! 题目:高速Fibonacci数算法 内容:先说说Fibonacci数列,它的定义是数列:f1,f2....fn有例如以下规律: ...