static NSView GetExtraButton(ActionSheetArguments arguments) { var newView = new NSView(); int height = 50; int width = 300; int i = 0; foreach (var button in arguments.Buttons) { var btn = new NSButton { Title = button, Tag = i }; btn.SetButtonType(NSButtonType.MomentaryPushIn); btn.Activated += (s, e) => { NSApplication.SharedApplication.EndSheet(NSApplication.SharedApplication.MainWindow.AttachedSheet, ((NSButton)s).Tag + 2); }; btn.Frame = new RectangleF(0, height * i, width, height); newView.AddSubview(btn); i++; } newView.Frame = new RectangleF(0, 0, width, height * i); return(newView); }
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"); }
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); }
public Task <string> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons) { var args = new ActionSheetArguments(title, cancel, destruction, buttons); MessagingCenter.Send(this, ActionSheetSignalName, args); return(args.Result.Task); }
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 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(); }
static void PresentPopUp(UIWindow window, UIAlertController alert, ActionSheetArguments arguments = null) { window.RootViewController = new UIViewController(); window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor(); window.WindowLevel = UIWindowLevel.Alert + 1; window.MakeKeyAndVisible(); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && arguments != null) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, n => { alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; }); arguments.Result.Task.ContinueWith(t => { NSNotificationCenter.DefaultCenter.RemoveObserver(observer); UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications(); }, TaskScheduler.FromCurrentSynchronizationContext()); alert.PopoverPresentationController.SourceView = window.RootViewController.View; alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow } if (!Forms.IsiOS9OrNewer) { // For iOS 8, we need to explicitly set the size of the window window.Frame = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height); } window.RootViewController.PresentViewController(alert, true, null); }
public FormsFlyout(ActionSheetArguments sheetOptions) { this.InitializeComponent(); options = sheetOptions; TitleBlock.Text = options.Title ?? string.Empty; OptionsList.ItemsSource = options.Buttons.ToList(); if (options.Cancel != null) { RightBtn.Content = options.Cancel; if (options.Destruction != null) { LeftBtn.Content = options.Destruction; } } else if (options.Destruction != null) { RightBtn.Content = options.Destruction; } LeftBtn.Visibility = LeftBtn.Content == null ? Visibility.Collapsed : Visibility.Visible; RightBtn.Visibility = RightBtn.Content == null ? Visibility.Collapsed : Visibility.Visible; }
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(); }
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); }
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); }
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 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 PresentAlert(UIWindow window, UIAlertController alert, ActionSheetArguments arguments = null) { window.RootViewController = new UIViewController(); window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor(); window.WindowLevel = UIWindowLevel.Alert + 1; window.MakeKeyAndVisible(); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && arguments != null) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); var observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, n => { alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; }); arguments.Result.Task.ContinueWith(t => { NSNotificationCenter.DefaultCenter.RemoveObserver(observer); UIDevice.CurrentDevice.EndGeneratingDeviceOrientationNotifications(); }, TaskScheduler.FromCurrentSynchronizationContext()); alert.PopoverPresentationController.SourceView = window.RootViewController.View; alert.PopoverPresentationController.SourceRect = window.RootViewController.View.Bounds; alert.PopoverPresentationController.PermittedArrowDirections = 0; // No arrow } window.RootViewController.PresentViewController(alert, true, null); }
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(); }
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); }
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); } }
public Task <string> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons) { var options = new ActionSheetArguments(title, cancel, destruction, buttons); var actionSheet = ActionSheetFlyout(options); actionSheet.ShowAt(Binding.Frame); return(options.Result.Task); }
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; } }
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) { //var list = new Avalonia.Controls.ListView //{ // Style = (Avalonia.Styling.Style)Avalonia.Application.Current.Resources["ActionSheetList"], // ItemsSource = options.Buttons //}; var dialog = new FormsContentDialog { //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 == Avalonia.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); }
public ActionSheetContent(ActionSheetArguments sheetOptions) { Initialize(); _options = sheetOptions; TitleBlock.Text = _options.Title ?? string.Empty; OptionsList.ItemsSource = _options.Buttons.ToList(); if (_options.FlowDirection == Maui.FlowDirection.RightToLeft) { TitleBlock.FlowDirection = UI.Xaml.FlowDirection.RightToLeft; OptionsList.FlowDirection = UI.Xaml.FlowDirection.RightToLeft; } else if (_options.FlowDirection == Maui.FlowDirection.LeftToRight) { TitleBlock.FlowDirection = UI.Xaml.FlowDirection.LeftToRight; OptionsList.FlowDirection = UI.Xaml.FlowDirection.LeftToRight; } if (_options.FlowDirection == Maui.FlowDirection.RightToLeft) { if (_options.Cancel != null) { LeftBtn.Content = _options.Cancel; if (_options.Destruction != null) { RightBtn.Content = _options.Destruction; } } else if (_options.Destruction != null) { LeftBtn.Content = _options.Destruction; } } else { if (_options.Cancel != null) { RightBtn.Content = _options.Cancel; if (_options.Destruction != null) { LeftBtn.Content = _options.Destruction; } } else if (_options.Destruction != null) { RightBtn.Content = _options.Destruction; } } LeftBtn.Visibility = LeftBtn.Content == null ? UI.Xaml.Visibility.Collapsed : UI.Xaml.Visibility.Visible; RightBtn.Visibility = RightBtn.Content == null ? UI.Xaml.Visibility.Collapsed : UI.Xaml.Visibility.Visible; }
public FormsFlyout(ActionSheetArguments sheetOptions) { this.InitializeComponent(); options = sheetOptions; TitleBlock.Text = options.Title ?? string.Empty; OptionsList.ItemsSource = options.Buttons.ToList(); if (options.FlowDirection == Xamarin.Forms.FlowDirection.RightToLeft) { TitleBlock.FlowDirection = Windows.UI.Xaml.FlowDirection.RightToLeft; OptionsList.FlowDirection = Windows.UI.Xaml.FlowDirection.RightToLeft; } else if (options.FlowDirection == Xamarin.Forms.FlowDirection.LeftToRight) { TitleBlock.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight; OptionsList.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight; } if (options.FlowDirection == Xamarin.Forms.FlowDirection.RightToLeft) { if (options.Cancel != null) { LeftBtn.Content = options.Cancel; if (options.Destruction != null) { RightBtn.Content = options.Destruction; } } else if (options.Destruction != null) { LeftBtn.Content = options.Destruction; } } else { if (options.Cancel != null) { RightBtn.Content = options.Cancel; if (options.Destruction != null) { LeftBtn.Content = options.Destruction; } } else if (options.Destruction != null) { RightBtn.Content = options.Destruction; } } LeftBtn.Visibility = LeftBtn.Content == null ? Visibility.Collapsed : Visibility.Visible; RightBtn.Visibility = RightBtn.Content == null ? Visibility.Collapsed : Visibility.Visible; }
void CancelActionSheet() { if (_currentActionSheet == null) { return; } _actionSheetOptions.SetResult(null); _actionSheetOptions = null; _currentActionSheet.IsOpen = false; _currentActionSheet = 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 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); } } }
public Task <string> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons) { var args = new ActionSheetArguments(title, cancel, destruction, buttons); if (IsPlatformEnabled) { MessagingCenter.Send(this, ActionSheetSignalName, args); } else { _pendingActions.Add(() => MessagingCenter.Send(this, ActionSheetSignalName, args)); } return(args.Result.Task); }
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); }
void PresentPre8ActionSheet(ActionSheetArguments arguments, IVisualElementRenderer pageRenderer) { var actionSheet = new UIActionSheet(arguments.Title, null, arguments.Cancel, arguments.Destruction, arguments.Buttons.ToArray()); actionSheet.ShowInView(pageRenderer.NativeView); actionSheet.Clicked += (o, args) => { string title = null; if (args.ButtonIndex != -1) { title = actionSheet.ButtonTitle(args.ButtonIndex); } arguments.Result.TrySetResult(title); }; }
public static string Render(this ActionSheetArguments actionSheet) { var parts = new List <string> { actionSheet.Title }; if (actionSheet.Destruction != null) { parts.Add($"[{actionSheet.Destruction}]"); } foreach (var button in actionSheet.Buttons) { parts.Add($"[{button}]"); } if (actionSheet.Cancel != null) { parts.Add($"[{actionSheet.Cancel}]"); } return(string.Join("\n", parts)); }
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; }
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 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; }