示例#1
0
        static void OnPageActionSheet(object sender, ActionSheetArguments options)
        {
            bool userDidSelect = false;
            var  flyoutContent = new FormsFlyout(options);

            var actionSheet = new Flyout
            {
                FlyoutPresenterStyle = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["FormsFlyoutPresenterStyle"],
                Placement            = Windows.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Full,
                Content = flyoutContent
            };

            flyoutContent.OptionSelected += (s, e) =>
            {
                userDidSelect = true;
                actionSheet.Hide();
            };

            actionSheet.Closed += (s, e) =>
            {
                if (!userDidSelect)
                {
                    options.SetResult(null);
                }
            };

            actionSheet.ShowAt(((Page)sender).GetOrCreateRenderer().ContainerElement);
        }
示例#2
0
        static void OnPageActionSheet(Page sender, ActionSheetArguments options)
        {
            bool userDidSelect = false;

            if (options.FlowDirection == FlowDirection.MatchParent)
            {
                if ((sender as IVisualElementController).EffectiveFlowDirection.IsRightToLeft())
                {
                    options.FlowDirection = FlowDirection.RightToLeft;
                }
                else if ((sender as IVisualElementController).EffectiveFlowDirection.IsLeftToRight())
                {
                    options.FlowDirection = FlowDirection.LeftToRight;
                }
            }

            var flyoutContent = new FormsFlyout(options);

            var actionSheet = new Flyout
            {
                FlyoutPresenterStyle = (Microsoft.UI.Xaml.Style)Microsoft.UI.Xaml.Application.Current.Resources["FormsFlyoutPresenterStyle"],
                Placement            = Microsoft.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Full,
                Content = flyoutContent
            };

            flyoutContent.OptionSelected += (s, e) =>
            {
                userDidSelect = true;
                actionSheet.Hide();
            };

            actionSheet.Closed += (s, e) =>
            {
                if (!userDidSelect)
                {
                    options.SetResult(null);
                }
            };

            try
            {
                actionSheet.ShowAt(((Page)sender).GetOrCreateRenderer().ContainerElement);
            }
            catch (ArgumentException)             // if the page is not in the visual tree
            {
                if (Forms.MainWindow.Content is FrameworkElement mainPage)
                {
                    actionSheet.ShowAt(mainPage);
                }
            }
        }