Пример #1
0
            void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
            {
                bool userDidSelect = false;

                if (arguments.FlowDirection == FlowDirection.MatchParent)
                {
                    // TODO: Check EffectiveFlowDirection
                }

                var actionSheetContent = new ActionSheetContent(arguments);

                var actionSheet = new Flyout
                {
                    Placement = UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Full,
                    Content   = actionSheetContent
                };

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

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

                try
                {
                    var pageParent = sender.ToPlatform(MauiContext).Parent as FrameworkElement;

                    if (pageParent != null)
                    {
                        actionSheet.ShowAt(pageParent);
                    }
                    else
                    {
                        arguments.SetResult(null);
                    }
                }
                catch (ArgumentException)                 // If the page is not in the visual tree
                {
                    if (UI.Xaml.Window.Current != null && UI.Xaml.Window.Current.Content is FrameworkElement mainPage)
                    {
                        actionSheet.ShowAt(mainPage);
                    }
                    else
                    {
                        arguments.SetResult(null);
                    }
                }
            }
Пример #2
0
            void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
            {
                bool userDidSelect = false;

                if (arguments.FlowDirection == FlowDirection.MatchParent)
                {
                    if (sender is IVisualElementController visualElementController)
                    {
                        if (visualElementController.EffectiveFlowDirection.IsRightToLeft())
                        {
                            arguments.FlowDirection = FlowDirection.RightToLeft;
                        }
                        else if (visualElementController.EffectiveFlowDirection.IsLeftToRight())
                        {
                            arguments.FlowDirection = FlowDirection.LeftToRight;
                        }
                    }
                }

                var actionSheetContent = new ActionSheetContent(arguments);

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

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

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

                try
                {
                    var current    = sender.ToPlatform(MauiContext);
                    var pageParent = current?.Parent as FrameworkElement;

                    if (pageParent != null)
                    {
                        actionSheet.ShowAt(pageParent);
                    }
                    else
                    {
                        if (current != null && current is FrameworkElement mainPage)
                        {
                            actionSheet.ShowAt(current);
                        }
                        else
                        {
                            arguments.SetResult(null);
                        }
                    }
                }
                catch (ArgumentException)                 // If the page is not in the visual tree
                {
                    if (UI.Xaml.Window.Current != null && UI.Xaml.Window.Current.Content is FrameworkElement mainPage)
                    {
                        actionSheet.ShowAt(mainPage);
                    }
                    else
                    {
                        arguments.SetResult(null);
                    }
                }
            }