Advertisement
FrayxRulez

FlyoutHelper

Feb 17th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Windows.Devices.Input;
  7. using Windows.Foundation;
  8. using Windows.UI.Xaml;
  9. using Windows.UI.Xaml.Controls;
  10. using Windows.UI.Xaml.Controls.Primitives;
  11.  
  12. namespace Telegram.Common
  13. {
  14.     public class FlyoutHelper
  15.     {
  16.         public static FlyoutBase GetAttachedFlyout(DependencyObject obj)
  17.         {
  18.             return (FlyoutBase)obj.GetValue(AttachedFlyoutProperty);
  19.         }
  20.  
  21.         public static void SetAttachedFlyout(DependencyObject obj, FlyoutBase value)
  22.         {
  23.             obj.SetValue(AttachedFlyoutProperty, value);
  24.         }
  25.  
  26.         public static readonly DependencyProperty AttachedFlyoutProperty =
  27.             DependencyProperty.RegisterAttached("AttachedFlyout", typeof(FlyoutBase), typeof(FlyoutHelper), new PropertyMetadata(null, OnAttachedFlyoutChanged));
  28.  
  29.         private static void OnAttachedFlyoutChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  30.         {
  31.             var sender = d as FrameworkElement;
  32.             var newValue = e.NewValue as FlyoutBase;
  33.  
  34.             if (newValue == null)
  35.             {
  36.                 FlyoutBase.SetAttachedFlyout(sender, null);
  37.                 sender.RightTapped -= OnRightTapped;
  38.                 sender.Holding -= OnHolding;
  39.             }
  40.             else
  41.             {
  42.                 FlyoutBase.SetAttachedFlyout(sender, newValue);
  43.                 sender.RightTapped += OnRightTapped;
  44.                 sender.Holding += OnHolding;
  45.             }
  46.         }
  47.  
  48.         private static void OnHolding(object sender, Windows.UI.Xaml.Input.HoldingRoutedEventArgs e)
  49.         {
  50.             if (e.PointerDeviceType == PointerDeviceType.Touch)
  51.             {
  52.                 FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
  53.             }
  54.         }
  55.  
  56.         private static void OnRightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
  57.         {
  58.             if (e.PointerDeviceType != PointerDeviceType.Touch)
  59.             {
  60.                 FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement