public override IDisposable Prompt(PromptConfig config) { var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert); UITextField txt = null; if (config.IsCancellable) { dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x => config.OnAction(new PromptResult(false, txt.Text.Trim()) ))); } dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => config.OnAction(new PromptResult(true, txt.Text.Trim()) ))); dlg.AddTextField(x => { this.SetInputType(x, config.InputType); x.Placeholder = config.Placeholder ?? String.Empty; if (config.Text != null) { x.Text = config.Text; } txt = x; }); return(this.Present(dlg)); }
public override IDisposable Prompt(PromptConfig config) { return(this.Present(() => { var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert); UITextField txt = null; if (config.IsCancellable) { dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x => config.OnAction(new PromptResult(false, txt.Text.Trim()) ))); } dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => config.OnAction(new PromptResult(true, txt.Text.Trim()) ))); dlg.AddTextField(x => { if (config.MaxLength != null) { txt.ShouldChangeCharacters = (tf, replace, range) => { var len = txt.Text.Length + replace.Length - range.Length; return len <= config.MaxLength.Value; }; } this.SetInputType(x, config.InputType); x.Placeholder = config.Placeholder ?? String.Empty; if (config.Text != null) { x.Text = config.Text; } txt = x; }); return dlg; })); }
public override IDisposable Prompt(PromptConfig config) { var dlg = new InputDialog { Title = config.Title, Text = config.Text, OkText = config.OkText, CancelText = config.CancelText, IsPassword = config.InputType == InputType.Password }; dlg.ShowDialog(); config.OnAction(new PromptResult(dlg.WasOk, dlg.Text)); return(new DisposableAction(dlg.Dispose)); }
public override IDisposable Prompt(PromptConfig config) { var prompt = new CustomMessageBox { Caption = config.Title, Message = config.Message, LeftButtonContent = config.OkText }; if (config.IsCancellable) { prompt.RightButtonContent = config.CancelText; } var password = new PasswordBox(); var inputScope = this.GetInputScope(config.InputType); var txt = new PhoneTextBox { InputScope = inputScope }; if (config.Text != null) { txt.Text = config.Text; } var isSecure = (config.InputType == InputType.NumericPassword || config.InputType == InputType.Password); if (isSecure) { prompt.Content = password; } else { prompt.Content = txt; } prompt.Dismissed += (sender, args) => { var ok = args.Result == CustomMessageBoxResult.LeftButton; var text = isSecure ? password.Password : txt.Text.Trim(); config.OnAction(new PromptResult(ok, text)); }; return(this.DispatchWithDispose(prompt.Show, prompt.Dismiss)); }
public override IDisposable Prompt(PromptConfig config) { Dispatch(() => { var dialog = new FormsContentDialog() { DataContext = config, Title = config.Title, // Content will be set IsPrimaryButtonEnabled = true, PrimaryButtonText = config.OkText, IsSecondaryButtonEnabled = config.IsCancellable, SecondaryButtonText = config.CancelText }; if (config.InputType == InputType.Password || config.InputType == InputType.NumericPassword) { var control = new PasswordPromptControl(); control.PasswordEdit.PasswordChanged += (s, e) => { config.Text = control.PasswordEdit.Password; if (config.OnTextChanged != null) { var args = new PromptTextChangedArgs() { Value = control.PasswordEdit.Password }; config.OnTextChanged(args); dialog.IsPrimaryButtonEnabled = args.IsValid; if (control.PasswordEdit.Password != args.Value) { control.PasswordEdit.Password = args.Value; } } }; dialog.Content = control; // First run of text changed if (config.OnTextChanged != null) { var args = new PromptTextChangedArgs() { Value = control.PasswordEdit.Password }; config.OnTextChanged(args); dialog.IsPrimaryButtonEnabled = args.IsValid; control.PasswordEdit.Password = args.Value; } } else { var control = new DefaultPromptControl(); control.TextEdit.TextChanged += (s, e) => { if (config.OnTextChanged != null) { var args = new PromptTextChangedArgs() { Value = control.TextEdit.Text }; config.OnTextChanged(args); dialog.IsPrimaryButtonEnabled = args.IsValid; if (control.TextEdit.Text != args.Value) { int selStart = control.TextEdit.SelectionStart; control.TextEdit.Text = args.Value; control.TextEdit.SelectionStart = selStart; } } }; dialog.Content = control; // First run of text changed if (config.OnTextChanged != null) { var args = new PromptTextChangedArgs() { Value = control.TextEdit.Text }; config.OnTextChanged(args); dialog.IsPrimaryButtonEnabled = args.IsValid; int selStart = control.TextEdit.SelectionStart; control.TextEdit.Text = args.Value; control.TextEdit.SelectionStart = selStart; } } dialog.PrimaryButtonClick += (s, e) => { HideContentDialog(); config.OnAction(new PromptResult(true, config.Text)); e.Cancel = true; }; dialog.SecondaryButtonClick += (s, e) => { HideContentDialog(); config.OnAction(new PromptResult(false, config.Text)); e.Cancel = true; }; ShowContentDialog(dialog); }); return(new DisposableAction(HideContentDialog)); }
public override IDisposable Prompt(PromptConfig config) { var prompt = new CustomMessageBox { Caption = config.Title, Message = config.Message, LeftButtonContent = config.OkText }; if (config.IsCancellable) prompt.RightButtonContent = config.CancelText; var password = new PasswordBox(); var inputScope = this.GetInputScope(config.InputType); var txt = new PhoneTextBox { InputScope = inputScope }; if (config.Text != null) txt.Text = config.Text; var isSecure = (config.InputType == InputType.NumericPassword || config.InputType == InputType.Password); if (isSecure) prompt.Content = password; else prompt.Content = txt; prompt.Dismissed += (sender, args) => { var ok = args.Result == CustomMessageBoxResult.LeftButton; var text = isSecure ? password.Password : txt.Text.Trim(); config.OnAction(new PromptResult(ok, text)); }; return this.DispatchWithDispose(prompt.Show, prompt.Dismiss); }
public override IDisposable Prompt(PromptConfig config) { var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert); UITextField txt = null; if (config.IsCancellable) { dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x => config.OnAction(new PromptResult(false, txt.Text.Trim()) ))); } dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => config.OnAction(new PromptResult(true, txt.Text.Trim()) ))); dlg.AddTextField(x => { this.SetInputType(x, config.InputType); x.Placeholder = config.Placeholder ?? String.Empty; if (config.Text != null) x.Text = config.Text; txt = x; }); return this.Present(dlg); }