wpf中的控件都直接或者间接继承自UIElement ,继承自它将拥有MouseUp和MouseDown两个方法,冒泡路由事件利用了控件都有这个方法的特性。单击一个元素,会触发他的单击事件,然后触发他的父元素,依次往上一级,直到顶级元素(一般为window)。附上代码
布局xaml:
<Window x:Class="冒泡路由事件.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:冒泡路由事件"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="329" MouseUp="