WPF Delegate委托整理
那啥,是从这里整理出来的,感谢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委托整理的更多相关文章
- 快速理解C#高级概念(一) Delegate委托
做.NET开发很久,最近重新温习<C#高级编程>一书.发现很多曾经似懂非懂的问题,其实也是能够慢慢钻研慢慢理解的. 所以,打算开写<C#高级编程系列>博文.其中会借鉴<C ...
- 关于js模拟c#的Delegate(委托)实现
这是我的第一篇博文,想来讲一讲js的函数.我的标题是js模拟c#的Delegate. 一.什么是Delegate(委托) 在jquery中有delegate函数,作用是将某个dom元素的标签的事件委托 ...
- (转)WPF学习资源整理
由于笔者正在学习WPF,所以整理出网络中部分WPF的学习资源,希望对同样在学习WPF的朋友们有所帮助. 首推刘铁猛的<深入浅出WPF>系列博文 1.深入浅出WPF(1)——什么是WPFht ...
- WPF学习资源整理
WPF(WindowsPresentation Foundation)是微软推出的基于Windows Vista的用户界面框架,属于.NET Framework 3.0的一部分.它提供了统一的编程模型 ...
- 使用 EPPlus 封装的 excel 表格导入功能 (二) delegate 委托 --永远滴神
使用 EPPlus 封装的 excel 表格导入功能 (二) delegate 委托 --永远滴神 前言 接上一篇 使用 EPPlus 封装的 excel 表格导入功能 (一) 前一篇的是大概能用但是 ...
- 【UE4 C++ 基础知识】<8> Delegate 委托
概念 定义 UE4中的delegate(委托)常用于解耦不同对象之间的关联:委托的触发者不与监听者有直接关联,两者通过委托对象间接地建立联系. 监听者通过将响应函数绑定到委托上,使得委托触发时立即收到 ...
- C# WPF 使用委托修改UI控件
近段时间在自学WPF,是一个完全不懂WPF的菜鸟,对于在线程中修改UI控件使用委托做一个记录,给自已以后查询也给需要的参考: 界面只放一个RichTextBox,在窗体启动时开起两个线程,调用两个函数 ...
- C# WPF 通过委托实现多窗口间的传值
在使用WPF开发的时候就不免会遇到需要两个窗口间进行传值操作,当然多窗口间传值的方法有很多种,本文介绍的是使用委托实现多窗口间的传值. 在上代码之前呢,先简单介绍一下什么是C#中的委托(如果只想了解如 ...
- C#中的委托 Delegate(委托 也叫代表,代表一类方法)
1. 委托类似与 C或C++中的函数指针,但委托是 面向对象的,并且是类型安全的 详情可查看官方文档:https://msdn.microsoft.com/en-us/library/ms173172 ...
随机推荐
- 按 Eclipse 开发喜好重新布置 cocos2dx 目录层次
[tonyfield 2013.08.29 ] 1. Cocos2dx 库的改动 处于个人的固执,花一天时间重新布置了cocos2dx 2.1.4的目录层次,将android平台无关的代码全数裁剪, ...
- 在phpmyadmin后台获取webshell方法汇总整理
方法一: CREATE TABLE `mysql`.`xiaoma` (`xiaoma1` TEXT NOT NULL ); INSERT INTO `mysql`.`xiaoma` (`xiaoma ...
- qt+boost::asio+tcp文件传输
客户端: void qt_boost::pbSendFileClicked(){ QString filename = ui.leFileName->text(); QByteArray ba ...
- Delphi经典网站收藏
http://delphi.icm.edu.pl/ 波兰的Delphi控件网站 http://dev.rdxx.com/Delphi/ 国内的编程网站 非常全面 http://oracle.ch ...
- jQuery EasyUI API 中文文档 - 链接按钮(linkbutton)
<html> <head> <script src="jquery-easyui/jquery.min.js"></script> ...
- 以对象管理资源——C++智能指针auto_ptr简介
auto_ptr是C++标准库提供的类模板,它可以帮助程序员自动管理用new表达式动态分配的单个对象.auto_ptr对象被初始化为指向由new表达式创建的对象,当auto_ptr对象的生命期结束时, ...
- Using Qt to build an Omi App for iOS (and Android)
JUNE 6, 2014 / HHARTZ Working on projects where the technology is pre-determined, it's often difficu ...
- 【css基础】垂直外边距的合并
近期在重温<CSS权威指南>,还是想把基础再打坚固点,如今对垂直外边距的合并问题进行简单总结. 1. 两个块级元素的外边距都大于0时,取那个最大值作为两个块级元素的垂直边距 请看以下一个小 ...
- java 状态模式 解说演示样例代码
package org.rui.pattern; import junit.framework.*; /** * 为了使同一个方法调用能够产生不同的行为,State 模式在代理(surrogate)的 ...
- Android 动态生成布局 (多层嵌套)
Android 除了能够载入xml文件,显示布局外,也能够代码生成布局,并通过setContentView(View view)方法显示布局.单独的一层布局,如一个主布局加一个控件(如Button\i ...