zoukankan      html  css  js  c++  java
  • 隧道路由事件

    学习WPF以来,一直以为隧道路由事件是由触发控件向其子控件传递的,见天才知道,原来隧道路由事件是从窗口想当前元素传递的!

    汗颜啊!

    贴上一段示例代码来说明一下:

    <Grid>
            <Border Height="50" Width="250" BorderBrush="Gray" BorderThickness="1" >
                <StackPanel Background="LightGray"
                            Orientation="Horizontal"
                            PreviewMouseLeftButtonUp="StackPanel_PreviewMouseLeftButtonUp"
                            MouseUp="StackPanel_MouseUp">
                    <TextBlock Name="YesTB" Width="50"
                               PreviewMouseLeftButtonUp="YesTB_PreviewMouseLeftButtonUp"
                               MouseUp="YesTB_MouseUp"
                               Background="Blue" >Yes</TextBlock>
                </StackPanel>
            </Border>
        </Grid>

    后台代码:

     private void YesTB_MouseUp(object sender, MouseButtonEventArgs e)
            {
                //MessageBox.Show("button");
                e.Handled = true;
            }
    
            private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
            {
                //MessageBox.Show("Panel");
            }
    
            private void YesTB_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("buttonPreview");
            }
    
            private void StackPanel_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("PanelPreview");
            }

    程序运行效果如图:

    当点击上图中的蓝色区域,首先会弹出“PanelPreivew”对话框,之后才弹出“buttonPreview”对话框。

    学习了!

  • 相关阅读:
    正则表达式的贪婪匹配(.*)和非贪婪匹配(.*?)
    jQuery + css 公告从左往右滚动
    C# process 使用方法
    存储过程与SQL的结合使用
    img标签的方方面面
    kibana 5.0.0-alpha5 安装
    es5.0 v5.0.0-alpha 编译安装
    奇怪的hosts文件
    阿里云 api 的文档拼写错误
    centos 7 systemd docker http proxy
  • 原文地址:https://www.cnblogs.com/my-sky/p/4563101.html
Copyright © 2011-2022 走看看