Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Windows.Devices.Input;
- using Windows.Foundation;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- namespace Telegram.Common
- {
- public class FlyoutHelper
- {
- public static FlyoutBase GetAttachedFlyout(DependencyObject obj)
- {
- return (FlyoutBase)obj.GetValue(AttachedFlyoutProperty);
- }
- public static void SetAttachedFlyout(DependencyObject obj, FlyoutBase value)
- {
- obj.SetValue(AttachedFlyoutProperty, value);
- }
- public static readonly DependencyProperty AttachedFlyoutProperty =
- DependencyProperty.RegisterAttached("AttachedFlyout", typeof(FlyoutBase), typeof(FlyoutHelper), new PropertyMetadata(null, OnAttachedFlyoutChanged));
- private static void OnAttachedFlyoutChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var sender = d as FrameworkElement;
- var newValue = e.NewValue as FlyoutBase;
- if (newValue == null)
- {
- FlyoutBase.SetAttachedFlyout(sender, null);
- sender.RightTapped -= OnRightTapped;
- sender.Holding -= OnHolding;
- }
- else
- {
- FlyoutBase.SetAttachedFlyout(sender, newValue);
- sender.RightTapped += OnRightTapped;
- sender.Holding += OnHolding;
- }
- }
- private static void OnHolding(object sender, Windows.UI.Xaml.Input.HoldingRoutedEventArgs e)
- {
- if (e.PointerDeviceType == PointerDeviceType.Touch)
- {
- FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
- }
- }
- private static void OnRightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
- {
- if (e.PointerDeviceType != PointerDeviceType.Touch)
- {
- FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement