首页 > 其他 > 详细

ContextFlyout 在10586或10240的使用

时间:2017-01-07 17:50:32      阅读:144      评论:0      收藏:0      [点我收藏+]

虽然ContextFlyout只能在红石以上版本使用,但可以采用附加属性的方法手动写一个

 

    public static class ContextFlyoutSetter
    {
        public static Windows.UI.Xaml.Controls.Primitives.FlyoutBase GetCompatibleContextFlyout(FrameworkElement obj)
        {
            return (Windows.UI.Xaml.Controls.Primitives.FlyoutBase)obj.GetValue(CompatibleContextFlyoutProperty);
        }

        public static void SetCompatibleContextFlyout(FrameworkElement obj, Windows.UI.Xaml.Controls.Primitives.FlyoutBase value)
        {
            obj.SetValue(CompatibleContextFlyoutProperty, value);
        }
        static readonly bool issupport = Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "ContextFlyout");
        // Using a DependencyProperty as the backing store for ContextFlyout.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CompatibleContextFlyoutProperty =
            DependencyProperty.RegisterAttached("CompatibleContextFlyout", typeof(Windows.UI.Xaml.Controls.Primitives.FlyoutBase), typeof(FrameworkElement), new PropertyMetadata(null, CompatibleContextFlyoutChanged));
        private static void CompatibleContextFlyoutChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            var uie=obj as FrameworkElement;
            if(uie!=null)
            {
                if(issupport )
                {
                    uie.ContextFlyout = e.NewValue as Windows.UI.Xaml.Controls.Primitives.FlyoutBase;
                }
                else
                {
                    Windows.UI.Xaml.Controls.Primitives.FlyoutBase.SetAttachedFlyout(uie, e.NewValue as Windows.UI.Xaml.Controls.Primitives.FlyoutBase);
                    if (e.NewValue!=null)
                    {
                        uie.Holding += Uie_Holding;
                        uie.RightTapped += Uie_RightTapped;
                    }
                    else
                    {
                        uie.Holding -= Uie_Holding;
                        uie.RightTapped -= Uie_RightTapped;
                    }
                }
            }
        }

        private static void Uie_Holding(object sender, Windows.UI.Xaml.Input.HoldingRoutedEventArgs e)
        {
            Windows.UI.Xaml.Controls.Primitives.FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
        }

        private static void Uie_RightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
        {
            Windows.UI.Xaml.Controls.Primitives.FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
        }
    }

 

最后使用的时候只需要这样

                            <localControls:ContextFlyoutSetter.CompatibleContextFlyout>
                                <MenuFlyout>

                                </MenuFlyout>
                            </localControls:ContextFlyoutSetter.CompatibleContextFlyout>

 

ContextFlyout 在10586或10240的使用

原文:http://www.cnblogs.com/yinyue200/p/6259811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!