PhoneApplicationPage 之观察 触摸事件 GIS

在PhoneApplicationPage上点击触摸任意位置  或者其子控件 都会触发OnManipulationStarted这个事件 ,可以通过重写这个事件来改变触发的响应,OnManipulationStarted这个事件的参数args 可以获得 触发的原始控件

namespace SilverlightTapHello2
{
    public partial class MainPage : PhoneApplicationPage
    {
        Random rand = new Random();
        Brush originalBrush;

        public MainPage()
        {
            InitializeComponent();
            originalBrush = txtblk.Foreground;
        }

        protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
        {
            if (args.OriginalSource == txtblk)
            {
                txtblk.Foreground = new SolidColorBrush(
                            Color.FromArgb(255, (byte)rand.Next(256),
                                                (byte)rand.Next(256),
                                                (byte)rand.Next(256)));
            }
            else
            {
                txtblk.Foreground = originalBrush;
            }

            args.Complete();
            base.OnManipulationStarted(args);
        }
    }
}

如果PhoneApplicationPage上的子控件定义了OnManipulationStarted这个事件  ,触摸子控件的时候就不会触发PhoneApplicationPage上(前提是args.Handled = true;)的触摸事件了,子控件没有定义的话 还是会触发PhoneApplicationPage上的OnManipulationStarted事件

原文地址:https://www.cnblogs.com/gisbeginner/p/2521585.html