protected override void OnAttached()
        {
            base.OnAttached();

            _expire.Elapsed += (sneder, args) =>
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    Debug.WriteLine("EXPIRE ELAPSED");
                    SetExpiration(false);
                    if (_notYetOpened)
                    {
                        AttachedProperties.SetLastClickWasTouch(AssociatedObject, false);
                    }
                }));
            };

            AssociatedObject.Initialized += (sneder, args) =>
            {
                Touch.FrameReported += Touch_FrameReported;
            };

            DependencyPropertyDescriptor.FromProperty(ContextMenu.PlacementTargetProperty, typeof(ContextMenu)).AddValueChanged(AssociatedObject, AssociatedObject_PlacementTargetChanged);

            if (AssociatedObject.IsOpen)
            {
                _notYetOpened = false;
            }

            AssociatedObject.Opened += AssociatedObject_Opened;

            AssociatedObject.Loaded += AssociatedObject_Loaded;
        }
 void UpdateLastClickWasTouch()
 {
     if (_target != null)
     {
         AttachedProperties.SetLastClickWasTouch(AssociatedObject, AttachedProperties.GetLastClickWasTouch(_target));
     }
 }
 private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
 {
     Debug.WriteLine("Touch_FrameReported");
     if (_notYetOpened)
     {
         AttachedProperties.SetLastClickWasTouch(AssociatedObject, true);
         SetExpiration(true);
     }
 }
Пример #4
0
        protected override void OnAttached()
        {
            base.OnAttached();

            DependencyPropertyDescriptor.FromProperty(FrameworkElement.ContextMenuProperty, typeof(FrameworkElement)).AddValueChanged(AssociatedObject, UpdateContextMenu);

            UpdateEventHandlers();
            if (AssociatedObject.ContextMenu != null)
            {
                AttachedProperties.SetLastClickWasTouch(AssociatedObject, AttachedProperties.GetLastClickWasTouch(AssociatedObject.ContextMenu));
            }
        }
Пример #5
0
        private void AssociatedObject_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource is UIElement srcUiel)
            {
                AttachedProperties.SetLastClickWasTouch(AssociatedObject, srcUiel.AreAnyTouchesOver);

                Debug.WriteLine("AssociatedObject_PreviewMouseDown, " + AttachedProperties.GetLastClickWasTouch(AssociatedObject).ToString());
            }
            else
            {
                Debug.WriteLine("AssociatedObject_PreviewMouseDown, null");
            }
        }
Пример #6
0
        private void Source_TouchDown(Object sender, TouchEventArgs e)
        {
            Debug.WriteLine("Source_TouchDown(object sender, TouchEventArgs e)");
            //TouchStarted = DateTime.Now;
            Timer touchTimer = new Timer(1);

            touchTimer.Elapsed += delegate
            {
                _targetMenu.Dispatcher.Invoke(new Action(() =>
                {
                    if (_targetMenu.IsOpen)
                    {
                        _wasOpenedWithTouch = true;
                        AttachedProperties.SetLastClickWasTouch(_targetMenu, _wasOpenedWithTouch);
                        //else if (!((e.OriginalSource as UIElement).AreAnyTouchesOver))
                        touchTimer.Stop();
                    }

                    //if (_wasOpenedWithTouch)
                }));
            };
            touchTimer.Start();
        }
Пример #7
0
        protected override void OnAttached()
        {
            _targetMenu = AssociatedObject;

            base.OnAttached();

            _targetMenu.Opened += (sneder, args) =>
            {
                //Debug.WriteLine("OpenedWithTouch: " + AttachedProperties.GetOpenedWithTouch(_targetMenu).ToString());
                //Debug.WriteLine(args.Source.GetType().FullName);
                AttachedProperties.SetLastClickWasTouch(_targetMenu, _wasOpenedWithTouch);
            };
            if (_targetMenu.IsLoaded)
            {
                Load();
            }
            else
            {
                _targetMenu.Loaded += TargetMenu_Loaded;
                //_targetMenu.Initialized += TargetMenu_Initialized;
                _targetMenu.ApplyTemplate();
                //_targetMenu.UpdateLayout();
            }
        }