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 导读和注意事项 各位技术爱好者,看完本文后 ...
随机推荐
- 【英语】Bingo口语笔记(42) - Got系列
- HDU 4766 Network
题意 就是找到一个 位置 使得路由器可以覆盖所有英雄 可以不覆盖主人自己, 找到距离 主人房子最近的位置,距离为多少 没想到 其实是道水题啊!! 分三个情况讨论 第一个情况 如果 ...
- Android手机部分名词浅谈
1.什么是Radio? Radio是无线通信模块的驱动程序,ROM是系统程序,radio负责网络通信,ROM和Radio可以分开刷,互不影响.如果您的手机刷新了ROM后有通讯方面的问题可以刷新radi ...
- delete archivelog all 无法彻底删除归档日志?
最近在因归档日志暴增,使用delete archivelog all貌似无法清除所有的归档日志,到底是什么原因呢? 1.演示环境 SQL> select * from v$version whe ...
- blender2.7.4安装three.js插件
将three.js-master\utils\exporters\blender\addons 下面的io_three文件夹,拷贝到blender安装目录:blender-2.74-windows64 ...
- 嵌入式 Linux下修改MAC地址
Linux下修改MAC地址 方法一: 1.关闭网卡设备ifconfig eth0 down2.修改MAC地址ifconfig eth0 hw ether MAC地址3.重启网卡ifconfig eth ...
- Codeforces Round #217 (Div. 2) c题
C. Mittens time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- C++中类的public,private,protected比较
当private,public,protected单纯的作为一个类中的成员权限设置时:private: 只能由该类中的函数.其友元函数访问,不能被任何其他访问,该类的对象也不能访问. protecte ...
- cefSharp在XP下使得程序崩溃记录
前言:这是一个奇葩的问题,到现在自己还没有搞明白问题出现在哪里,但是从问题总算是解决了,希望看到此文章的大牛,如果知道问题出在什么地方,可以告知一下. [一个在XP系统下面应用程序崩溃问题] 资源: ...
- linux grub
grub 是目前使用最广泛的linux引导装载程序,旧的lilo这个引导装载程序很少见了,grub优点: 支持较多哦的文件系统,可以使用grub主程序在文件系统中查找内核文件名 启动的时候,可以自行编 ...