Routed Events【pluralsight】
Routing Strategies:
- Direct
- Bubbling
- Tunneling
WHy use them?
- Any UIElement can be a listener
- Common handlers
- Visual Tree Communication
- Event Setter and Event Trigger
Routed Event Example:
<Window x:Class="CustomControlDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="350"
Height="220"
ButtonBase.Click="Window_Click"> //listen to the RoutedEvent:ButtonBase.Click and handle RoutedEvent using Window_Click
<Grid>
<StackPanel Margin="20" ButtonBase.Click="StackPanel_Click"> //listen to the RoutedEvent:ButtonBase.Click and handle RoutedEvent using StackPanel_Click
<Border BorderBrush="Red" BorderThickness="5">
<TextBlock Margin="5"
FontSize="18"
Text="This is a TextBlock" />
</Border>
<Button Margin="10"
Click="Button_Click" //handle the Button.Click event using Button_Click handler
Content="Click me" />
</StackPanel>
</Grid>
</Window>
namespace CustomControlDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Button_Click(object sender, RoutedEventArgs e)
{
//Button层的event handler,由于ButtonBase.Click是routedEvent所以可以向上bubble
} private void StackPanel_Click(object sender, RoutedEventArgs e)
{
e.Handled = true; //StackPanel层的event handler,不继续向上传
e.Handled = false; //StackPanel层的event handler,继续向上传
} private void Window_Click(object sender, RoutedEventArgs e)
{
//Window层的event handler,已传到最上层
}
}
}
我们也可以不在xaml写handler,直接用后台控制
namespace CustomControlDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
AddHandler(Button.ClickEvent, new RoutedEventHandler(Window_Click), true); //即使e.Handled = true;我们也要routedevent继续传到window层
} private void Button_Click(object sender, RoutedEventArgs e)
{
//Button层的event handler,由于ButtonBase.Click是routedEvent所以可以向上bubble
} private void StackPanel_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
} private void Window_Click(object sender, RoutedEventArgs e)
{
}
}
}
Custom Routed Events
- register your event
- choose your routing strategy
- provide add and remove CLR wrapper
- Raise your event
Routed Events【pluralsight】的更多相关文章
- Generic【Pluralsight】
prepare Employee Structure namespace CollectIt { public class Employee { public string Name { get; s ...
- 【概率论】2-2:独立事件(Independent Events)
title: [概率论]2-2:独立事件(Independent Events) categories: Mathematic Probability keywords: Independent Ev ...
- 【概率论】1-4:事件的的并集(Union of Events and Statical Swindles)
title: [概率论]1-4:事件的的并集(Union of Events and Statical Swindles) categories: Mathematic Probability key ...
- 【jquery】基础知识
jquery简介 1 jquery是什么 jquery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. jQuery是继prototype之后 ...
- 企业IT管理员IE11升级指南【7】—— Win7和Win8.1上的IE11功能对比
企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...
- 【Javascript】重新绑定默认事件
更多内容,请移步 JSCON-简时空 在有一种场景下,你想先屏蔽掉默认的系统事件,而在特定条件下又重新绑定回去. [场景]H5页面,动画欢迎界面,共6帧:想在前5帧中屏蔽掉默认的touchmove事件 ...
- 【故障处理】队列等待之enq IV - contention案例
[故障处理]队列等待之enq IV - contention案例 1.1 BLOG文档结构图 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也 ...
- 【故障处理】告警日志报“ORA-01565 Unable To open Spfile”
[故障处理]告警日志报"ORA-01565 Unable To open Spfile" 1.1 BLOG文档结构图 1.2 故障分析及解决过程 1.2.1 故障环境介绍 项 ...
- 【ASH】如何导出视图DBA_HIST_ACTIVE_SESS_HISTORY的查询结果数据
[ASH]如何导出视图DBA_HIST_ACTIVE_SESS_HISTORY的查询结果数据 1.1 BLOG文档结构图 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱好者,看完本文后 ...
随机推荐
- 《摇滚南京》——"人生下来就是孤独"
昨天是纪录片<摇滚南京>东南大学站的展映分享会 我不是一个摇滚迷,作为学渣狗看论文.码代码的时候会塞个耳机,平时其实民谣听得更多一点,摇滚觉得有点高大上.所以整好趁着学校有活动,也跟着高大 ...
- CentOS安装tomcat
一.下载Tomcat 1..进入Tomcat官网:http://tomcat.apache.org/ 左侧选择相应的版本 点击Tomcat 6.0后 点击tar.gz下载apache-tomcat-6 ...
- MySQL与Oracle 差异比较之四条件循环语句
循环语句 编号 类别 ORACLE MYSQL 注释 1 IF语句使用不同 IF iv_weekly_day = 'MON' THEN ii_weekly_day := 'MON';ELS ...
- Eclipse for PHP Developers + xamp +xdebug
php 开发环境搭建 1.安装xamp 我的版本是v3.2.1 2.安装下载“Eclipse for PHP Developers”解压即可使用 3.配置“Eclipse for PHP Develo ...
- 嵌入式 Linux下修改MAC地址
Linux下修改MAC地址 方法一: 1.关闭网卡设备ifconfig eth0 down2.修改MAC地址ifconfig eth0 hw ether MAC地址3.重启网卡ifconfig eth ...
- hdu 4927 java求组合数(大数)
import java.util.Scanner; import java.math.BigInteger; public class Main { private static int [] a = ...
- Delphi VclSkin使用教程
1. TSkinData TSkinData 主要用于美化你的程序, 只要把TSkinData控件放下去,它就能自动美化所有窗体. 属性 Active: 使用或取消对程序的美化. DisableT ...
- linux下安装filezilla客户端遇到的问题
访问filezilla ./filezilla 出现error while loading shared libraries : libpng12.so.o 缺少libpng12.so.o这个文件 解 ...
- 解决g++:command not found(centos7.0)
问题背景,因为装了虚拟机,系统为centos7.0,由于是纯净版,没有gcc,使用命令yum install gcc安装了gcc,但是没安装g++,导致g++:command not found问题. ...
- Firefox 对条件判断语句块内的函数声明的处理与其他浏览器有差异
标准参考 函数声明和函数表达式 定义一个函数有两种途径:函数声明和函数表达式. 函数声明: function Identifier ( FormalParameterList opt ) { Func ...