void AView.IOnClickListener.OnClick(AView v) { var button = (AButton)v; _arguments.SetResult(button.Text); Hide(); }
public static void ShowActionSheet(PlatformRenderer platformRender, ActionSheetArguments arguments) { MessageDialog messageDialog = new MessageDialog( platformRender.Toplevel as Window, DialogFlags.DestroyWithParent, MessageType.Other, ButtonsType.Cancel, null); SetDialogTitle(arguments.Title, messageDialog); SetButtonText(arguments.Cancel, ButtonsType.Cancel, messageDialog); SetDestructionButton(arguments.Destruction, messageDialog); AddExtraButtons(arguments, messageDialog); int result = messageDialog.Run(); if ((ResponseType)result == ResponseType.Cancel) { arguments.SetResult(arguments.Cancel); } else if ((ResponseType)result == ResponseType.Reject) { arguments.SetResult(arguments.Destruction); } messageDialog.Destroy(); }
async void OnPageActionSheet(Page sender, ActionSheetArguments options) { var list = new System.Windows.Controls.ListView { Style = (System.Windows.Style)System.Windows.Application.Current.Resources["ActionSheetList"], ItemsSource = options.Buttons }; var dialog = new LightContentDialog { Content = list, }; if (options.Title != null) { dialog.Title = options.Title; } list.SelectionChanged += (s, e) => { if (list.SelectedItem != null) { dialog.Hide(); options.SetResult((string)list.SelectedItem); } }; /*_page.KeyDown += (window, e) => * { * if (e.Key == System.Windows.Input.Key.Escape) * { * dialog.Hide(); * options.SetResult(LightContentDialogResult.None.ToString()); * } * };*/ if (options.Cancel != null) { dialog.IsSecondaryButtonEnabled = true; dialog.SecondaryButtonText = options.Cancel; } if (options.Destruction != null) { dialog.IsPrimaryButtonEnabled = true; dialog.PrimaryButtonText = options.Destruction; } LightContentDialogResult result = await dialog.ShowAsync(); if (result == LightContentDialogResult.Secondary) { options.SetResult(options.Cancel); } else if (result == LightContentDialogResult.Primary) { options.SetResult(options.Destruction); } }
void ListItemSelected(object sender, ItemClickEventArgs e) { var selection = (string)e.ClickedItem; options.SetResult(selection); OptionSelected?.Invoke(this, null); }
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); } } }
async void OnPageActionSheet(Page sender, ActionSheetArguments options) { List <string> buttons = options.Buttons.ToList(); var list = new Windows.UI.Xaml.Controls.ListView { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], ItemsSource = buttons, IsItemClickEnabled = true }; var dialog = new ContentDialog { Template = (Windows.UI.Xaml.Controls.ControlTemplate)Windows.UI.Xaml.Application.Current.Resources["MyContentDialogControlTemplate"], Content = list, Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetStyle"] }; if (options.Title != null) { dialog.Title = options.Title; } list.ItemClick += (s, e) => { dialog.Hide(); options.SetResult((string)e.ClickedItem); }; _actionSheetOptions = options; if (options.Cancel != null) { dialog.SecondaryButtonText = options.Cancel; } if (options.Destruction != null) { dialog.PrimaryButtonText = options.Destruction; } ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Secondary) { options.SetResult(options.Cancel); } else if (result == ContentDialogResult.Primary) { options.SetResult(options.Destruction); } }
static Flyout ActionSheetFlyout(ActionSheetArguments options) { bool userDidSelect = false; var flyoutContent = new FormsFlyout(options); var actionSheet = new Flyout { FlyoutPresenterStyle = (Style)Application.Current.Resources["FormsFlyoutPresenterStyle"], Placement = FlyoutPlacementMode.Full, Content = flyoutContent }; flyoutContent.OptionSelected += (s, e) => { userDidSelect = true; actionSheet.Hide(); }; actionSheet.Closed += (s, e) => { if (!userDidSelect) { options.SetResult(null); } }; return(actionSheet); }
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); }
void OnActionSheetRequested(Page sender, ActionSheetArguments arguments) { var builder = new AlertDialog.Builder(this); builder.SetTitle(arguments.Title); string[] items = arguments.Buttons.ToArray(); builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which])); if (arguments.Cancel != null) { builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel)); } if (arguments.Destruction != null) { builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction)); } AlertDialog dialog = builder.Create(); builder.Dispose(); //to match current functionality of renderer we set cancelable on outside //and return null dialog.SetCanceledOnTouchOutside(true); dialog.CancelEvent += (o, e) => arguments.SetResult(null); dialog.Show(); }
public void ActionSheetArgumentsConstructor() { tlog.Debug(tag, $"ActionSheetArgumentsConstructor START"); var testingTarget = new ActionSheetArguments("ActionSheetArguments", "cancel", "destruction", Buttons); Assert.IsNotNull(testingTarget, "Can't create success object ActionSheetArguments."); Assert.IsInstanceOf <ActionSheetArguments>(testingTarget, "Should return ActionSheetArguments instance."); tlog.Debug(tag, "Buttons : " + testingTarget.Buttons); tlog.Debug(tag, "Cancel : " + testingTarget.Cancel); tlog.Debug(tag, "Destruction : " + testingTarget.Destruction); tlog.Debug(tag, "Result : " + testingTarget.Result); tlog.Debug(tag, "Title : " + testingTarget.Title); try { testingTarget.SetResult("OK"); } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception : Failed!"); } tlog.Debug(tag, $"ActionSheetArgumentsConstructor END"); }
private static void AddExtraButtons(ActionSheetArguments arguments, MessageDialog messageDialog) { var vbox = messageDialog.VBox; // As we are not showing any message in this dialog, we just // hide default container and avoid it from using space vbox.Children[0].Hide(); if (arguments.Buttons.Any()) { for (int i = 0; i < arguments.Buttons.Count(); i++) { var button = new Gtk.Button(); button.Label = arguments.Buttons.ElementAt(i); button.Clicked += (o, e) => { arguments.SetResult(button.Label); messageDialog.Destroy(); }; button.Show(); vbox.PackStart(button, false, false, 0); } } }
public void DisplayActionSheet() { var page = new ContentPage() { IsPlatformEnabled = true }; ActionSheetArguments args = null; MessagingCenter.Subscribe(this, Page.ActionSheetSignalName, (Page sender, ActionSheetArguments e) => args = e); var task = page.DisplayActionSheet("Title", "Cancel", "Destruction", "Other 1", "Other 2"); Assert.AreEqual("Title", args.Title); Assert.AreEqual("Destruction", args.Destruction); Assert.AreEqual("Cancel", args.Cancel); Assert.AreEqual("Other 1", args.Buttons.First()); Assert.AreEqual("Other 2", args.Buttons.Skip(1).First()); bool completed = false; var continueTask = task.ContinueWith(t => completed = true); args.SetResult("Cancel"); continueTask.Wait(); Assert.True(completed); }
void OnActionSheetRequested(Page sender, ActionSheetArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } var builder = new DialogBuilder(Activity); builder.SetTitle(arguments.Title); string[] items = arguments.Buttons.ToArray(); builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which])); if (arguments.Cancel != null) { builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel)); } if (arguments.Destruction != null) { builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction)); } var dialog = builder.Create(); builder.Dispose(); //to match current functionality of renderer we set cancelable on outside //and return null dialog.SetCanceledOnTouchOutside(true); dialog.SetCancelEvent((o, e) => arguments.SetResult(null)); dialog.Show(); }
void OnActionSheetRequested(Page sender, ActionSheetArguments arguments) { // Verify that the page making the request is part of this activity if (!PageIsInThisContext(sender)) { return; } var builder = new DialogBuilder(Activity); builder.SetTitle(arguments.Title); string[] items = arguments.Buttons.ToArray(); builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which])); if (arguments.Cancel != null) { builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel)); } if (arguments.Destruction != null) { builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction)); } var dialog = builder.Create(); builder.Dispose(); //to match current functionality of renderer we set cancelable on outside //and return null if (arguments.FlowDirection == FlowDirection.MatchParent && sender is IVisualElementController ve) { dialog.Window.DecorView.UpdateFlowDirection(ve); } else if (arguments.FlowDirection == FlowDirection.LeftToRight) { dialog.Window.DecorView.LayoutDirection = LayoutDirection.Ltr; } else if (arguments.FlowDirection == FlowDirection.RightToLeft) { dialog.Window.DecorView.LayoutDirection = LayoutDirection.Rtl; } dialog.SetCanceledOnTouchOutside(true); dialog.SetCancelEvent((o, e) => arguments.SetResult(null)); dialog.Show(); dialog.GetListView().TextDirection = GetTextDirection(sender, arguments.FlowDirection); LayoutDirection layoutDirection = GetLayoutDirection(sender, arguments.FlowDirection); if (arguments.Cancel != null) { ((dialog.GetButton((int)DialogButtonType.Positive).Parent) as global::Android.Views.View).LayoutDirection = layoutDirection; } if (arguments.Destruction != null) { ((dialog.GetButton((int)DialogButtonType.Negative).Parent) as global::Android.Views.View).LayoutDirection = layoutDirection; } }
public override bool Tap(string text) { if (arguments.Cancel == text || arguments.Destruction == text || arguments.Buttons.Contains(text)) { arguments.SetResult(text); return(true); } else { return(false); } }
void CancelActionSheet() { if (_currentActionSheet == null) { return; } _actionSheetOptions.SetResult(null); _actionSheetOptions = null; _currentActionSheet.IsOpen = false; _currentActionSheet = null; }
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); } } }
static void OnPageActionSheet(object sender, ActionSheetArguments options) { bool userDidSelect = false; var flyoutContent = new FormsFlyout(options); var actionSheet = new Flyout { FlyoutPresenterStyle = (global::Windows.UI.Xaml.Style)global::Windows.UI.Xaml.Application.Current.Resources["FormsFlyoutPresenterStyle"], Placement = global::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); } }; try { actionSheet.ShowAt(((Page)sender).GetOrCreateRenderer().ContainerElement); } catch (ArgumentException) // if the page is not in the visual tree { if (Window.Current.Content is FrameworkElement mainPage) { actionSheet.ShowAt(mainPage); } } }
void OnPageActionSheet(Page sender, ActionSheetArguments options) { var finalArguments = new List<string>(); if (options.Destruction != null) finalArguments.Add(options.Destruction); if (options.Buttons != null) finalArguments.AddRange(options.Buttons); if (options.Cancel != null) finalArguments.Add(options.Cancel); var list = new Windows.UI.Xaml.Controls.ListView { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], ItemsSource = finalArguments, IsItemClickEnabled = true }; list.ItemClick += (s, e) => { _currentActionSheet.IsOpen = false; _currentActionSheet = null; options.SetResult((string)e.ClickedItem); }; _actionSheetOptions = options; Size size = Device.Info.ScaledScreenSize; var stack = new StackPanel { MinWidth = 100, Children = { new TextBlock { Text = options.Title ?? string.Empty, Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleTextBlockStyle"], Margin = new Windows.UI.Xaml.Thickness(0, 0, 0, 10), Visibility = options.Title != null ? Visibility.Visible : Visibility.Collapsed }, list } }; var border = new Border { Child = stack, BorderBrush = new SolidColorBrush(Colors.White), BorderThickness = new Windows.UI.Xaml.Thickness(1), Padding = new Windows.UI.Xaml.Thickness(15), Background = (Brush)Windows.UI.Xaml.Application.Current.Resources["AppBarBackgroundThemeBrush"] }; Windows.UI.Xaml.Controls.Grid.SetRow(border, 1); Windows.UI.Xaml.Controls.Grid.SetColumn(border, 1); var container = new Windows.UI.Xaml.Controls.Grid { RowDefinitions = { new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } }, ColumnDefinitions = { new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } }, Height = size.Height, Width = size.Width, Children = { border } }; var bgPopup = new Popup { Child = new Canvas { Width = size.Width, Height = size.Height, Background = new SolidColorBrush(new Windows.UI.Color { A = 128, R = 0, G = 0, B = 0 }) } }; bgPopup.IsOpen = true; _currentActionSheet = new Popup { ChildTransitions = new TransitionCollection { new PopupThemeTransition() }, IsLightDismissEnabled = true, Child = container }; _currentActionSheet.Closed += (s, e) => { bgPopup.IsOpen = false; CancelActionSheet(); }; if (Device.Idiom == TargetIdiom.Phone) { double height = WindowBounds.Height; stack.Height = height; stack.Width = size.Width; border.BorderThickness = new Windows.UI.Xaml.Thickness(0); _currentActionSheet.Height = height; _currentActionSheet.VerticalOffset = size.Height - height; } _currentActionSheet.IsOpen = true; }
void ActionSheetSignalNameHandler(XPage sender, ActionSheetArguments arguments) { Native.Dialog dialog = Native.Dialog.CreateDialog(Forms.NativeParent); dialog.Title = arguments.Title; Box box = new Box(dialog); if (null != arguments.Destruction) { Native.Button destruction = new Native.Button(dialog) { Text = arguments.Destruction, Style = ButtonStyle.Text, TextColor = EColor.Red, AlignmentX = -1 }; destruction.Clicked += (s, evt) => { arguments.SetResult(arguments.Destruction); dialog.Dismiss(); }; destruction.Show(); box.PackEnd(destruction); } foreach (string buttonName in arguments.Buttons) { Native.Button button = new Native.Button(dialog) { Text = buttonName, BackgroundColor = buttonName.ToColor(), AlignmentX = -1, MinimumWidth = 400 }; if (button.BackgroundColor == EColor.White || button.BackgroundColor == ColorExtensions.Azure) { button.TextColor = EColor.Black; } button.Clicked += (s, evt) => { arguments.SetResult(buttonName); dialog.Dismiss(); }; button.Show(); box.PackEnd(button); } box.Show(); dialog.Content = box; if (null != arguments.Cancel) { EButton cancel = new EButton(dialog) { Text = arguments.Cancel }; dialog.NegativeButton = cancel; cancel.Clicked += (s, evt) => { dialog.Dismiss(); }; } dialog.BackButtonPressed += (s, evt) => { dialog.Dismiss(); }; dialog.Show(); }
async void OnPageActionSheet(Page sender, ActionSheetArguments options) { List<string> buttons = options.Buttons.ToList(); var list = new Windows.UI.Xaml.Controls.ListView { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], ItemsSource = buttons, IsItemClickEnabled = true }; var dialog = new ContentDialog { Template = (Windows.UI.Xaml.Controls.ControlTemplate)Windows.UI.Xaml.Application.Current.Resources["MyContentDialogControlTemplate"], Content = list, Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetStyle"] }; if (options.Title != null) dialog.Title = options.Title; list.ItemClick += (s, e) => { dialog.Hide(); options.SetResult((string)e.ClickedItem); }; TypedEventHandler<CoreWindow, CharacterReceivedEventArgs> onEscapeButtonPressed = delegate(CoreWindow window, CharacterReceivedEventArgs args) { if (args.KeyCode == 27) { dialog.Hide(); options.SetResult(ContentDialogResult.None.ToString()); } }; Window.Current.CoreWindow.CharacterReceived += onEscapeButtonPressed; _actionSheetOptions = options; if (options.Cancel != null) dialog.SecondaryButtonText = options.Cancel; if (options.Destruction != null) dialog.PrimaryButtonText = options.Destruction; ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Secondary) options.SetResult(options.Cancel); else if (result == ContentDialogResult.Primary) options.SetResult(options.Destruction); Window.Current.CoreWindow.CharacterReceived -= onEscapeButtonPressed; }
void ActionSheetSignalNameHandler(Page sender, ActionSheetArguments arguments) { // Verify that the page making the request is child of this platform if (!PageIsChildOfPlatform(sender)) { return; } Native.Dialog alert = Native.Dialog.CreateDialog(Forms.NativeParent); alert.Title = arguments.Title; Box box = new Box(alert); if (null != arguments.Destruction) { Native.Button destruction = new Native.Button(alert) { Text = arguments.Destruction, Style = ButtonStyle.Text, TextColor = EColor.Red, AlignmentX = -1 }; destruction.Clicked += (s, evt) => { arguments.SetResult(arguments.Destruction); alert.Dismiss(); }; destruction.Show(); box.PackEnd(destruction); } foreach (string buttonName in arguments.Buttons) { Native.Button button = new Native.Button(alert) { Text = buttonName, Style = ButtonStyle.Text, AlignmentX = -1 }; button.Clicked += (s, evt) => { arguments.SetResult(buttonName); alert.Dismiss(); }; button.Show(); box.PackEnd(button); } box.Show(); alert.Content = box; if (null != arguments.Cancel) { EButton cancel = new EButton(Forms.NativeParent) { Text = arguments.Cancel }; alert.NegativeButton = cancel; cancel.Clicked += (s, evt) => { alert.Dismiss(); }; } alert.BackButtonPressed += (s, evt) => { alert.Dismiss(); }; alert.Show(); _alerts.Add(alert); alert.Dismissed += (s, e) => _alerts.Remove(alert); }
void PresentAlert(ActionSheetArguments arguments, IVisualElementRenderer pageRenderer) { var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet); var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() }; if (arguments.Cancel != null) { alert.AddAction(CreateActionWithWindowHide(arguments.Cancel, UIAlertActionStyle.Cancel, () => arguments.SetResult(arguments.Cancel), window)); } if (arguments.Destruction != null) { alert.AddAction(CreateActionWithWindowHide(arguments.Destruction, UIAlertActionStyle.Destructive, () => arguments.SetResult(arguments.Destruction), window)); } foreach (var label in arguments.Buttons) { if (label == null) { continue; } var blabel = label; alert.AddAction(CreateActionWithWindowHide(blabel, UIAlertActionStyle.Default, () => arguments.SetResult(blabel), window)); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, n => { alert.PopoverPresentationController.SourceRect = pageRenderer.ViewController.View.Bounds; }); arguments.Result.Task.ContinueWith(t => { NSNotificationCenter.DefaultCenter.RemoveObserver(observer); UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications(); }, TaskScheduler.FromCurrentSynchronizationContext()); alert.PopoverPresentationController.SourceView = pageRenderer.ViewController.View; alert.PopoverPresentationController.SourceRect = pageRenderer.ViewController.View.Bounds; alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow } PresentAlert(window, alert); }
static async void OnPageActionSheet(object sender, ActionSheetArguments options) { List <string> buttons = options.Buttons.ToList(); var list = new Windows.UI.Xaml.Controls.ListView { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], ItemsSource = buttons, IsItemClickEnabled = true }; var dialog = new ContentDialog { Template = (Windows.UI.Xaml.Controls.ControlTemplate)Windows.UI.Xaml.Application.Current.Resources["MyContentDialogControlTemplate"], Content = list, Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetStyle"] }; if (options.Title != null) { dialog.Title = options.Title; } list.ItemClick += (s, e) => { dialog.Hide(); options.SetResult((string)e.ClickedItem); }; TypedEventHandler <CoreWindow, CharacterReceivedEventArgs> onEscapeButtonPressed = delegate(CoreWindow window, CharacterReceivedEventArgs args) { if (args.KeyCode == 27) { dialog.Hide(); options.SetResult(ContentDialogResult.None.ToString()); } }; Window.Current.CoreWindow.CharacterReceived += onEscapeButtonPressed; if (options.Cancel != null) { dialog.SecondaryButtonText = options.Cancel; } if (options.Destruction != null) { dialog.PrimaryButtonText = options.Destruction; } ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Secondary) { options.SetResult(options.Cancel); } else if (result == ContentDialogResult.Primary) { options.SetResult(options.Destruction); } Window.Current.CoreWindow.CharacterReceived -= onEscapeButtonPressed; }
void PresentActionSheet(ActionSheetArguments arguments) { var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet); // Clicking outside of an ActionSheet is an implicit cancel on iPads. If we don't handle it, it freezes the app. if (arguments.Cancel != null || UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { alert.AddAction(UIAlertAction.Create(arguments.Cancel ?? "", UIAlertActionStyle.Cancel, _ => arguments.SetResult(arguments.Cancel))); } if (arguments.Destruction != null) { alert.AddAction(UIAlertAction.Create(arguments.Destruction, UIAlertActionStyle.Destructive, _ => arguments.SetResult(arguments.Destruction))); } foreach (var label in arguments.Buttons) { if (label == null) { continue; } var blabel = label; alert.AddAction(UIAlertAction.Create(blabel, UIAlertActionStyle.Default, _ => arguments.SetResult(blabel))); } PresentPopUp(Window, alert, arguments); }
public ActionSheet(ActionSheetArguments arguments) { Element = new Div(); Element.ClassName = "modal-dialog"; var content = new Div(); content.ClassName = "modal-content"; var header = new Div(); header.ClassName = "modal-header"; var h4 = new Heading(4) { Text = arguments.Title }; header.AppendChild(h4); content.AppendChild(header); var body = new Div(); body.ClassName = "modal-body"; content.AppendChild(body); _buttons = new List <Button>(); foreach (var button in arguments.Buttons) { var btnBody = new Div(); btnBody.Style.MarginBottom = 5; var btn = new Button(button); btn.Style.Width = "100%"; btn.ClassName = "btn"; btn.Click += (s, e) => SetResult(button); _buttons.Add(btn); btnBody.AppendChild(btn); body.AppendChild(btnBody); } if (!string.IsNullOrEmpty(arguments.Cancel)) { var footer = new Div(); footer.ClassName = "modal-footer"; _cancelButton = new Button(arguments.Cancel); _cancelButton.ClassName = "btn -btn-default"; _cancelButton.Click += (s, e) => SetResult(arguments.Cancel); footer.AppendChild(_cancelButton); content.AppendChild(footer); } Element.AppendChild(content); void SetResult(string result) { arguments.SetResult(result); } }
void OnPageActionSheet(Page sender, ActionSheetArguments options) { var finalArguments = new List <string>(); if (options.Destruction != null) { finalArguments.Add(options.Destruction); } if (options.Buttons != null) { finalArguments.AddRange(options.Buttons); } if (options.Cancel != null) { finalArguments.Add(options.Cancel); } var list = new Windows.UI.Xaml.Controls.ListView { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], ItemsSource = finalArguments, IsItemClickEnabled = true }; list.ItemClick += (s, e) => { _currentActionSheet.IsOpen = false; options.SetResult((string)e.ClickedItem); }; _actionSheetOptions = options; Size size = Device.Info.ScaledScreenSize; var stack = new StackPanel { MinWidth = 100, Children = { new TextBlock { Text = options.Title ?? string.Empty, Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleTextBlockStyle"], Margin = new Windows.UI.Xaml.Thickness(0, 0, 0, 10), Visibility = options.Title != null ? Visibility.Visible : Visibility.Collapsed }, list } }; var border = new Border { Child = stack, BorderBrush = new SolidColorBrush(Colors.White), BorderThickness = new Windows.UI.Xaml.Thickness(1), Padding = new Windows.UI.Xaml.Thickness(15), Background = (Brush)Windows.UI.Xaml.Application.Current.Resources["AppBarBackgroundThemeBrush"] }; Windows.UI.Xaml.Controls.Grid.SetRow(border, 1); Windows.UI.Xaml.Controls.Grid.SetColumn(border, 1); var container = new Windows.UI.Xaml.Controls.Grid { RowDefinitions = { new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, new Windows.UI.Xaml.Controls.RowDefinition { Height = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } }, ColumnDefinitions = { new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) }, new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(0, Windows.UI.Xaml.GridUnitType.Auto) }, new Windows.UI.Xaml.Controls.ColumnDefinition { Width = new Windows.UI.Xaml.GridLength(1, Windows.UI.Xaml.GridUnitType.Star) } }, Height = size.Height, Width = size.Width, Children = { border } }; var bgPopup = new Popup { Child = new Canvas { Width = size.Width, Height = size.Height, Background = new SolidColorBrush(new Windows.UI.Color { A = 128, R = 0, G = 0, B = 0 }) } }; bgPopup.IsOpen = true; _currentActionSheet = new Popup { ChildTransitions = new TransitionCollection { new PopupThemeTransition() }, IsLightDismissEnabled = true, Child = container }; _currentActionSheet.Closed += (s, e) => { bgPopup.IsOpen = false; CancelActionSheet(); }; if (Device.Idiom == TargetIdiom.Phone) { double height = WindowBounds.Height; stack.Height = height; stack.Width = size.Width; border.BorderThickness = new Windows.UI.Xaml.Thickness(0); _currentActionSheet.Height = height; _currentActionSheet.VerticalOffset = size.Height - height; } _currentActionSheet.IsOpen = true; }
void PresentActionSheet(ActionSheetArguments arguments) { var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet); var window = new UIWindow { BackgroundColor = Colors.Transparent.ToUIColor() }; // Clicking outside of an ActionSheet is an implicit cancel on iPads. If we don't handle it, it freezes the app. if (arguments.Cancel != null || UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { alert.AddAction(CreateActionWithWindowHide(arguments.Cancel ?? "", UIAlertActionStyle.Cancel, () => arguments.SetResult(arguments.Cancel), window)); } if (arguments.Destruction != null) { alert.AddAction(CreateActionWithWindowHide(arguments.Destruction, UIAlertActionStyle.Destructive, () => arguments.SetResult(arguments.Destruction), window)); } foreach (var label in arguments.Buttons) { if (label == null) { continue; } var blabel = label; alert.AddAction(CreateActionWithWindowHide(blabel, UIAlertActionStyle.Default, () => arguments.SetResult(blabel), window)); } PresentPopUp(window, alert, arguments); }
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); } } }
async void OnPageActionSheet(Page sender, ActionSheetArguments options) { List<string> buttons = options.Buttons.ToList(); var list = new Windows.UI.Xaml.Controls.ListView { Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetList"], ItemsSource = buttons, IsItemClickEnabled = true }; var dialog = new ContentDialog { Template = (Windows.UI.Xaml.Controls.ControlTemplate)Windows.UI.Xaml.Application.Current.Resources["MyContentDialogControlTemplate"], Content = list, Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["ActionSheetStyle"] }; if (options.Title != null) dialog.Title = options.Title; list.ItemClick += (s, e) => { dialog.Hide(); options.SetResult((string)e.ClickedItem); }; _actionSheetOptions = options; if (options.Cancel != null) dialog.SecondaryButtonText = options.Cancel; if (options.Destruction != null) dialog.PrimaryButtonText = options.Destruction; ContentDialogResult result = await dialog.ShowAsync(); if (result == ContentDialogResult.Secondary) options.SetResult(options.Cancel); else if (result == ContentDialogResult.Primary) options.SetResult(options.Destruction); }
void OnActionSheetRequest(Page sender, ActionSheetArguments arguments) { // Verify that the page making the request is child of this platform if (!_platform.PageIsChildOfPlatform(sender)) { return; } var alert = Native.Dialog.CreateDialog(Forms.NativeParent); alert.Title = arguments.Title; var box = new Box(alert); if (null != arguments.Destruction) { var destruction = new Native.Button(alert) { Text = arguments.Destruction, AlignmentX = -1 }; destruction.SetWatchTextStyle(); //TextColor should be set after applying style destruction.TextColor = EColor.Red; destruction.Clicked += (s, evt) => { arguments.SetResult(arguments.Destruction); alert.Dismiss(); }; destruction.Show(); box.PackEnd(destruction); } foreach (string buttonName in arguments.Buttons) { var button = new Native.Button(alert) { Text = buttonName, AlignmentX = -1 }; button.SetWatchTextStyle(); button.Clicked += (s, evt) => { arguments.SetResult(buttonName); alert.Dismiss(); }; button.Show(); box.PackEnd(button); } box.Show(); alert.Content = box; if (null != arguments.Cancel) { var cancel = new EButton(Forms.NativeParent) { Text = arguments.Cancel }; alert.NegativeButton = cancel; cancel.Clicked += (s, evt) => { alert.Dismiss(); }; } alert.BackButtonPressed += (s, evt) => { alert.Dismiss(); }; alert.Show(); _alerts.Add(alert); alert.Dismissed += (s, e) => _alerts.Remove(alert); }
void PresentAlert(ActionSheetArguments arguments) { var alert = UIAlertController.Create(arguments.Title, null, UIAlertControllerStyle.ActionSheet); var window = new UIWindow { BackgroundColor = Color.Transparent.ToUIColor() }; if (arguments.Cancel != null) { alert.AddAction(CreateActionWithWindowHide(arguments.Cancel, UIAlertActionStyle.Cancel, () => arguments.SetResult(arguments.Cancel), window)); } if (arguments.Destruction != null) { alert.AddAction(CreateActionWithWindowHide(arguments.Destruction, UIAlertActionStyle.Destructive, () => arguments.SetResult(arguments.Destruction), window)); } foreach (var label in arguments.Buttons) { if (label == null) { continue; } var blabel = label; alert.AddAction(CreateActionWithWindowHide(blabel, UIAlertActionStyle.Default, () => arguments.SetResult(blabel), window)); } PresentAlert(window, alert, arguments); }
static void ActionSheetSignalNameHandler(Page sender, ActionSheetArguments arguments) { Native.Dialog alert = new Native.Dialog(Forms.Context.MainWindow); alert.Title = arguments.Title; Box box = new Box(alert); if (null != arguments.Destruction) { Native.Button destruction = new Native.Button(alert) { Text = arguments.Destruction, TextColor = EColor.Red, AlignmentX = -1 }; destruction.Clicked += (s, evt) => { arguments.SetResult(arguments.Destruction); alert.Dismiss(); }; destruction.Show(); box.PackEnd(destruction); } foreach (string buttonName in arguments.Buttons) { Native.Button button = new Native.Button(alert) { Text = buttonName, AlignmentX = -1 }; button.Clicked += (s, evt) => { arguments.SetResult(buttonName); alert.Dismiss(); }; button.Show(); box.PackEnd(button); } box.Show(); alert.Content = box; if (null != arguments.Cancel) { EButton cancel = new EButton(Forms.Context.MainWindow) { Text = arguments.Cancel }; alert.NegativeButton = cancel; cancel.Clicked += (s, evt) => { alert.Dismiss(); }; } alert.BackButtonPressed += (s, evt) => { alert.Dismiss(); }; alert.Show(); }