/// <inheritdoc /> public override void Show(string caption, object content, ButtonConfig[] buttonConfigs, bool isFullScreen = false) { Guard.ArgumentNotNull(() => buttonConfigs); var messageBox = new CustomMessageBoxWindow(caption, content, buttonConfigs, isFullScreen); messageBox.ShowDialog(); }
private void ContentCalloutButtonClicked(object sender, System.EventArgs e) { var callout = SimpleIoc.Default.GetInstance<ICallout>(); var okButtonConfig = new ButtonConfig("I Agree", () => { Debug.WriteLine("AGREED!"); }, isEnabled: false); var cancelButtonConfig = new ButtonConfig("I Decline"); var buttonConfigs = new[] { okButtonConfig, cancelButtonConfig }; var customCallout = SimpleIoc.Default.GetInstance<ICustomCallout>(); var customCalloutContent = customCallout.GetContent(okButtonConfig); callout.Show("Content Callout", customCalloutContent, buttonConfigs); }
public object GetContent(ButtonConfig okButtonConfig) { var inflatorservice = (LayoutInflater)Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService); var containerView = inflatorservice.Inflate(Resource.Layout.customcallout, null, false); var @switch = (Switch)containerView.FindViewById(Resource.Id.switch1); @switch.CheckedChange += (sender, args) => { okButtonConfig.IsEnabled = args.IsChecked; }; return containerView; }
public object GetContent(ButtonConfig okButtonConfig) { var stackpanel = new StackPanel(); ////var label = new TextBlock(); ////label.Text = "Do you agree?"; ////stackpanel.Children.Add(label); ////var checkBox = new CheckBox(); ////checkBox.Checked += (o, args) => { okButtonConfig.IsEnabled = checkBox.IsChecked.HasValue && checkBox.IsChecked.Value; }; ////stackpanel.Children.Add(checkBox); return null; }
private void Button_OnClick_ContentCallout(object sender, RoutedEventArgs e) { var callout = SimpleIoc.Default.GetInstance<ICallout>(); var okButtonConfig = new ButtonConfig("I Agree", () => { Debug.WriteLine("Agreed!"); }, isEnabled: false); var cancelButtonConfig = new ButtonConfig("I Decline", () => { Debug.WriteLine("Disagreed!"); }); var buttonConfigs = new[] { okButtonConfig, cancelButtonConfig }; var panel = new StackPanel(); panel.Children.Add(new TextBlock { Text = "This is a short message.", TextWrapping = TextWrapping.Wrap, }); var checkBox = new CheckBox { Content = "Agree" }; checkBox.Checked += (o, args) => { okButtonConfig.IsEnabled = true; }; checkBox.Unchecked += (o, args) => { okButtonConfig.IsEnabled = false; }; panel.Children.Add(checkBox); callout.Show("Content Callout", panel, buttonConfigs); }
public object GetContent(ButtonConfig okButtonConfig) { var panel = new UIView(); panel.Frame = new CGRect(0, 0, 200, 50); var label = new UILabel(); label.Text = "Do you agree?"; label.SizeToFit(); label.AdjustsFontSizeToFitWidth = true; panel.Add(label); var uiSwitch = new UISwitch(); uiSwitch.Frame = new CGRect(200, 0, 27, 27); uiSwitch.ValueChanged += (o, args) => { okButtonConfig.IsEnabled = uiSwitch.On; }; panel.Add(uiSwitch); return panel; }
private void Button_OnClick_ContentCallout(object sender, RoutedEventArgs e) { var okButtonConfig = new ButtonConfig("I Agree", () => { Debug.WriteLine("Agreed!"); }, isEnabled: false); var cancelButtonConfig = new ButtonConfig("I Decline", () => { Debug.WriteLine("Disagreed!"); }); var buttonConfigs = new[] { okButtonConfig, cancelButtonConfig }; var panel = new StackPanel(); panel.Children.Add(new TextBlock { Text = "This is a short message.", TextWrapping = TextWrapping.Wrap, }); var checkBox = new CheckBox { Content = "Agree" }; checkBox.Checked += (o, args) => { okButtonConfig.IsEnabled = true; }; checkBox.Unchecked += (o, args) => { okButtonConfig.IsEnabled = false; }; panel.Children.Add(checkBox); this.callout.Show( this.CaptionTextBox.Text, panel, buttonConfigs, this.FullScreenCheckBox.IsChecked.Value); }
/// <inheritdoc /> public override void Show(string caption, object content, ButtonConfig[] buttonConfigs, bool isFullScreen = false) { Guard.ArgumentNotNull(() => buttonConfigs); ButtonConfig leftButton = null; ButtonConfig rightButton = null; if (buttonConfigs.Length < this.MinNumberOfButtons || buttonConfigs.Length > this.MaxNumberOfButtons) { throw new ArgumentException(string.Format("'buttonConfigs' supports a minimum of {0} and a maximum of {1} buttons", this.MinNumberOfButtons, this.MaxNumberOfButtons)); } var messageBox = new CustomMessageBox { Caption = caption, IsFullScreen = isFullScreen }; if (buttonConfigs.Length >= 1) { leftButton = buttonConfigs[0]; messageBox.LeftButtonContent = leftButton.Text; } if (buttonConfigs.Length == 2) { rightButton = buttonConfigs[1]; messageBox.RightButtonContent = rightButton.Text; } var stringContent = content as string; if (stringContent != null) { messageBox.Message = stringContent; messageBox.Content = null; } else { ////var hyperlinkButton = content as HyperlinkButton; ////if (hyperlinkButton != null) ////{ //// TiltEffect.SetIsTiltEnabled(hyperlinkButton, true); ////} messageBox.Message = null; messageBox.Content = content; } messageBox.Dismissed += (s1, e1) => { switch (e1.Result) { case CustomMessageBoxResult.LeftButton: if (leftButton != null) { leftButton.Action(); } break; case CustomMessageBoxResult.RightButton: if (rightButton != null) { rightButton.Action(); } break; case CustomMessageBoxResult.None: break; default: break; } messageBox.Content = null; // This is to avoid ArgumentException 'Value does not fall within the expected range' }; Deployment.Current.Dispatcher.BeginInvoke(() => { messageBox.Show(); }); }
/// <inheritdoc /> public override void Show(string caption, object content, ButtonConfig[] buttonConfigs, bool isFullScreen = false) { Guard.ArgumentNotNull(() => buttonConfigs); var stringContent = content as string; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var alertController = UIAlertController.Create(caption, string.Empty, UIAlertControllerStyle.Alert); if (stringContent != null) { alertController.Message = stringContent; } var view = content as UIView; if (view != null) { UIViewController v = new UIViewController(); v.View = view; alertController.SetValueForKey(v, new NSString("contentViewController")); //alertController.View.AddSubview(view); } foreach (var buttonConfig in buttonConfigs) { var alertAction = UIAlertAction.Create(buttonConfig.Text, UIAlertActionStyle.Default, x => buttonConfig.Action()); EventHandler<bool> buttonConfigOnEnabledChanged = null; buttonConfigOnEnabledChanged = (sender, isEnabled) => { alertAction.Enabled = isEnabled; }; buttonConfig.EnabledChanged += buttonConfigOnEnabledChanged; alertAction.Enabled = buttonConfig.IsEnabled; alertController.AddAction(alertAction); } this.dispatcherService.CheckBeginInvokeOnUI(() => { UIApplication.SharedApplication.PresentInternal(alertController); }); } else { var alertView = new UIAlertView { AlertViewStyle = UIAlertViewStyle.Default, Title = caption }; if (stringContent != null) { alertView.Message = stringContent; } var view = content as UIView; if (view != null) { alertView.AddSubview(view); } foreach (var buttonConfig in buttonConfigs) { alertView.AddButton(buttonConfig.Text); } alertView.Clicked += (s, e) => { buttonConfigs[e.ButtonIndex].Action(); }; this.dispatcherService.CheckBeginInvokeOnUI(() => { alertView.Show(); }); } }
/// <inheritdoc /> public override void Show(string caption, object content, ButtonConfig[] buttonConfigs, bool isFullScreen = false) { Guard.ArgumentNotNull(() => buttonConfigs); ButtonConfig primaryButton = null; ButtonConfig secondaryButton = null; if (buttonConfigs.Length < this.MinNumberOfButtons || buttonConfigs.Length > this.MaxNumberOfButtons) { throw new ArgumentException(string.Format("'buttonConfigs' supports a minimum of {0} and a maximum of {1} buttons", this.MinNumberOfButtons, this.MaxNumberOfButtons)); } if (buttonConfigs.Length >= 1) { primaryButton = buttonConfigs[0]; } if (buttonConfigs.Length == 2) { secondaryButton = buttonConfigs[1]; } //http://www.reflectionit.nl/blog/2015/windows-10-xaml-tips-messagedialog-and-contentdialog //http://www.kunal-chowdhury.com/2013/02/win8dev-tutorial-windows-store-winrt-messagedialog.html //https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.contentdialog.aspx //ContentDialog contentDialog = new ContentDialog(); == TODO CHeck for examples var stringContent = content as string; if (stringContent != null) { var messageDialog = new MessageDialog(stringContent, caption); if (primaryButton != null) { messageDialog.Commands.Add(new UICommand(primaryButton.Text, delegate { primaryButton.Action(); })); } if (secondaryButton != null) { messageDialog.Commands.Add(new UICommand(secondaryButton.Text, delegate { secondaryButton.Action(); })); } messageDialog.ShowAsync(); } else { var contentDialog = new ContentDialog { Title = caption, //RequestedTheme = ElementTheme.Dark, #if WINDOWS_UWP FullSizeDesired = isFullScreen, #endif //MaxWidth = this.ActualWidth // Required for Mobile! }; var cp = new ContentPresenter(); cp.Content = content; #if WINDOWS_APP contentDialog.ContentWrapper = cp; #else contentDialog.Content = cp; #endif EventHandler <bool> primaryButtonOnEnabledChanged = null; if (primaryButton != null) { primaryButtonOnEnabledChanged = (sender, isEnabled) => { contentDialog.IsPrimaryButtonEnabled = isEnabled; }; primaryButton.EnabledChanged += primaryButtonOnEnabledChanged; contentDialog.PrimaryButtonText = primaryButton.Text; contentDialog.IsPrimaryButtonEnabled = primaryButton.IsEnabled; contentDialog.PrimaryButtonClick += delegate { primaryButton.Action(); }; } EventHandler <bool> secondaryButtonOnEnabledChanged = null; if (secondaryButton != null) { secondaryButtonOnEnabledChanged = (sender, isEnabled) => { contentDialog.IsSecondaryButtonEnabled = isEnabled; }; secondaryButton.EnabledChanged += secondaryButtonOnEnabledChanged; contentDialog.SecondaryButtonText = secondaryButton.Text; contentDialog.IsSecondaryButtonEnabled = secondaryButton.IsEnabled; contentDialog.SecondaryButtonClick += delegate { secondaryButton.Action(); }; } #if WINDOWS_APP // Windows Store Apps ContentDialog does not return an async task // when calling ShowAsync(). TaskCompletionSource comes to the rescue! var tcs = new TaskCompletionSource <object>(); contentDialog.Closed += (sender, args) => { tcs.TrySetResult(null); }; contentDialog.ShowAsync(); var unsubscribeTask = tcs.Task; #else var unsubscribeTask = contentDialog.ShowAsync().AsTask(); #endif unsubscribeTask.ContinueWith( ct => { if (primaryButton != null && primaryButtonOnEnabledChanged != null) { primaryButton.EnabledChanged -= primaryButtonOnEnabledChanged; } if (secondaryButton != null && secondaryButtonOnEnabledChanged != null) { secondaryButton.EnabledChanged -= secondaryButtonOnEnabledChanged; } }); } }
/// <inheritdoc /> public override void Show(string caption, object content, ButtonConfig[] buttonConfigs, bool isFullScreen = false) { Guard.ArgumentNotNull(() => buttonConfigs); ButtonConfig positiveButton = null; ButtonConfig negativeButton = null; ButtonConfig neutralButton = null; if (buttonConfigs.Length < this.MinNumberOfButtons || buttonConfigs.Length > this.MaxNumberOfButtons) { throw new ArgumentException(string.Format("'buttonConfigs' supports a minimum of {0} and a maximum of {1} buttons", this.MinNumberOfButtons, this.MaxNumberOfButtons)); } var currentActivity = GetActivity(); var alertBuilder = new AlertDialog.Builder(currentActivity); alertBuilder.SetTitle(caption); alertBuilder.SetCancelable(isFullScreen); var stringContent = content as string; if (stringContent != null) { alertBuilder.SetMessage(stringContent); } var viewContent = content as View; if (viewContent != null) { alertBuilder.SetView(viewContent); } AlertDialog alertDialog = null; if (buttonConfigs.Length >= 1) { positiveButton = buttonConfigs[0]; alertBuilder.SetPositiveButton(positiveButton.Text, (senderAlert, args) => { positiveButton.Action(); }); positiveButton.EnabledChanged += (sender, isEnabled) => { UpdateEnabledChanged(alertDialog, DialogButtonType.Positive, isEnabled); }; } if (buttonConfigs.Length >= 2) { negativeButton = buttonConfigs[1]; alertBuilder.SetNegativeButton(negativeButton.Text, (senderAlert, args) => { negativeButton.Action(); }); negativeButton.EnabledChanged += (sender, isEnabled) => { UpdateEnabledChanged(alertDialog, DialogButtonType.Negative, isEnabled); }; } if (buttonConfigs.Length == 3) { neutralButton = buttonConfigs[2]; alertBuilder.SetNeutralButton(neutralButton.Text, (senderAlert, args) => { neutralButton.Action(); }); neutralButton.EnabledChanged += (sender, isEnabled) => { UpdateEnabledChanged(alertDialog, DialogButtonType.Neutral, isEnabled); }; } // dispatch the alert to the UI thread this.dispatcherService.CheckBeginInvokeOnUI( () => { alertDialog = alertBuilder.Create(); alertDialog.Show(); if (positiveButton != null) { UpdateEnabledChanged(alertDialog, DialogButtonType.Positive, positiveButton.IsEnabled); } if (negativeButton != null) { UpdateEnabledChanged(alertDialog, DialogButtonType.Negative, negativeButton.IsEnabled); } if (neutralButton != null) { UpdateEnabledChanged(alertDialog, DialogButtonType.Neutral, neutralButton.IsEnabled); } }); }
/// <inheritdoc /> public override void Show(string caption, object content, ButtonConfig[] buttonConfigs, bool isFullScreen = false) { Guard.ArgumentNotNull(() => buttonConfigs); ButtonConfig primaryButton = null; ButtonConfig secondaryButton = null; if (buttonConfigs.Length < this.MinNumberOfButtons || buttonConfigs.Length > this.MaxNumberOfButtons) { throw new ArgumentException(string.Format("'buttonConfigs' supports a minimum of {0} and a maximum of {1} buttons", this.MinNumberOfButtons, this.MaxNumberOfButtons)); } if (buttonConfigs.Length >= 1) { primaryButton = buttonConfigs[0]; } if (buttonConfigs.Length == 2) { secondaryButton = buttonConfigs[1]; } //http://www.reflectionit.nl/blog/2015/windows-10-xaml-tips-messagedialog-and-contentdialog //http://www.kunal-chowdhury.com/2013/02/win8dev-tutorial-windows-store-winrt-messagedialog.html //https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.contentdialog.aspx //ContentDialog contentDialog = new ContentDialog(); == TODO CHeck for examples var stringContent = content as string; if (stringContent != null) { var messageDialog = new MessageDialog(stringContent, caption); if (primaryButton != null) { messageDialog.Commands.Add(new UICommand(primaryButton.Text, delegate { primaryButton.Action(); })); } if (secondaryButton != null) { messageDialog.Commands.Add(new UICommand(secondaryButton.Text, delegate { secondaryButton.Action(); })); } messageDialog.ShowAsync(); } else { var contentDialog = new ContentDialog { Title = caption, //RequestedTheme = ElementTheme.Dark, #if WINDOWS_UWP FullSizeDesired = isFullScreen, #endif //MaxWidth = this.ActualWidth // Required for Mobile! }; var cp = new ContentPresenter(); cp.Content = content; #if WINDOWS_APP contentDialog.ContentWrapper = cp; #else contentDialog.Content = cp; #endif EventHandler<bool> primaryButtonOnEnabledChanged = null; if (primaryButton != null) { primaryButtonOnEnabledChanged = (sender, isEnabled) => { contentDialog.IsPrimaryButtonEnabled = isEnabled; }; primaryButton.EnabledChanged += primaryButtonOnEnabledChanged; contentDialog.PrimaryButtonText = primaryButton.Text; contentDialog.IsPrimaryButtonEnabled = primaryButton.IsEnabled; contentDialog.PrimaryButtonClick += delegate { primaryButton.Action(); }; } EventHandler<bool> secondaryButtonOnEnabledChanged = null; if (secondaryButton != null) { secondaryButtonOnEnabledChanged = (sender, isEnabled) => { contentDialog.IsSecondaryButtonEnabled = isEnabled; }; secondaryButton.EnabledChanged += secondaryButtonOnEnabledChanged; contentDialog.SecondaryButtonText = secondaryButton.Text; contentDialog.IsSecondaryButtonEnabled = secondaryButton.IsEnabled; contentDialog.SecondaryButtonClick += delegate { secondaryButton.Action(); }; } #if WINDOWS_APP // Windows Store Apps ContentDialog does not return an async task // when calling ShowAsync(). TaskCompletionSource comes to the rescue! var tcs = new TaskCompletionSource<object>(); contentDialog.Closed += (sender, args) => { tcs.TrySetResult(null); }; contentDialog.ShowAsync(); var unsubscribeTask = tcs.Task; #else var unsubscribeTask = contentDialog.ShowAsync().AsTask(); #endif unsubscribeTask.ContinueWith( ct => { if (primaryButton != null && primaryButtonOnEnabledChanged != null) { primaryButton.EnabledChanged -= primaryButtonOnEnabledChanged; } if (secondaryButton != null && secondaryButtonOnEnabledChanged != null) { secondaryButton.EnabledChanged -= secondaryButtonOnEnabledChanged; } }); } }