private async Task <Credential> DoSignInInUIThread(CredentialRequestInfo credentialRequestInfo) { var signInDialog = this; // Create the ContentDialog that contains the SignInDialog var contentDialog = new ContentDialog { SecondaryButtonText = "cancel", PrimaryButtonText = "sign in", FullSizeDesired = true, Content = signInDialog, }; contentDialog.PrimaryButtonClick += ContentDialogOnPrimaryButtonClick; // Bind the Title so the ContentDialog Title is the SignInDialog title (that will be initialized later) contentDialog.SetBinding(ContentDialog.TitleProperty, new Binding { Path = new PropertyPath("Title"), Source = signInDialog }); contentDialog.SetBinding(ContentDialog.IsPrimaryButtonEnabledProperty, new Binding { Path = new PropertyPath("IsReady"), Source = signInDialog }); contentDialog.Closed += ContentDialogOnClosed; // be sure the SignInDialog is deactivated when pressing back button // Show the content dialog var _ = contentDialog.ShowAsync(); // don't await else that would block here // Wait for the creation of the credential Credential crd; try { crd = await signInDialog.WaitForCredentialAsync(credentialRequestInfo); } finally { // Close the content dialog contentDialog.Hide(); } return(crd); }
internal async Task <(ContentDialogResult dialogResult, string name)> GetNewProjectName() { var template = App.CurrentMainPage.Resources["TextInputContent"] as DataTemplate; var inputViewModel = new TextInputViewModel { Question = "Enter name for new Project." }; (ContentDialogResult dialogResult, string name)result = default; var contentControl = new ContentControl { DataContext = inputViewModel, ContentTemplate = template }; var dialog = new ContentDialog { DataContext = inputViewModel, Title = "New Project", Content = contentControl, CloseButtonText = "Cancel", CloseButtonCommand = new RelayCommand(() => { result.dialogResult = ContentDialogResult.Secondary; }), DefaultButton = ContentDialogButton.Primary, PrimaryButtonText = "Create" }; var binding = new Binding { Path = new PropertyPath(nameof(TextInputViewModel.Answer)), Mode = BindingMode.OneWay }; typeof(Binding).GetProperty("DataContext").SetValue(binding, inputViewModel); dialog.SetBinding(ContentDialog.PrimaryButtonCommandParameterProperty, binding); dialog.PrimaryButtonCommand = new RelayCommand <string>(answer => { if (!string.IsNullOrWhiteSpace(answer)) { result.dialogResult = ContentDialogResult.Primary; result.name = answer; dialog.Hide(); } }, answer => !string.IsNullOrWhiteSpace(answer)); await dialog.ShowAsync(); return(result); }
/// <summary> /// Save the position where the map was clicked /// </summary> private async void mapWithMyLocation_MapClick(MapControl sender, MapInputEventArgs args) { BasicGeoposition tappedGeoPosition = args.Location.Position; // Creates the text box var PointName = new TextBox { Margin = new Thickness(10), PlaceholderText = "Point Name" }; var PointNotes = new TextBox { Margin = new Thickness(10), PlaceholderText = "Point Notes" }; // Creates the StackPanel with the content var contentPanel = new StackPanel(); contentPanel.Children.Add(new TextBlock { Text = "Enter your Point Name and Note", Margin = new Thickness(10), TextWrapping = TextWrapping.WrapWholeWords }); contentPanel.Children.Add(PointName); contentPanel.Children.Add(PointNotes); // Creates the Point dialog ContentDialog _pointDialog = new ContentDialog { PrimaryButtonText = "Save", IsPrimaryButtonEnabled = false, SecondaryButtonText = "Cancel", Title = "Save Point", Content = contentPanel }; // Report that the dialog has been opened to avoid overlapping _pointDialog.Opened += delegate { // HACK - opacity set to 0 to avoid seeing behind dialog Window.Current.Content.Opacity = 1; }; // Report that the dialog has been closed to enable it again _pointDialog.Closed += delegate { // HACK - opacity set to 1 to reset the window to original options Window.Current.Content.Opacity = 1; }; // Clear inserted password for next logins _pointDialog.PrimaryButtonClick += delegate { DatabaseHelperClass Db_Helper = new DatabaseHelperClass();//Creating object for DatabaseHelperClass.cs from ViewModel/DatabaseHelperClass.cs if (PointName != null) { Db_Helper.Insert(new Points(PointName.Text, PointNotes.Text, tappedGeoPosition.Latitude.ToString(), tappedGeoPosition.Longitude.ToString())); DB_PointsList = dbcpoints.GetAllPoints(); //Get all DB points listBoxobj.ItemsSource = DB_PointsList.OrderByDescending(i => i.Id).ToList(); //Binding DB data to LISTBOX and Latest points ID can Display first. AddMapIcon(tappedGeoPosition, PointName.Text); } }; // Set the binding to enable/disable the accept button _pointDialog.SetBinding(ContentDialog.IsPrimaryButtonEnabledProperty, new Binding { Source = PointName, Path = new PropertyPath("Point"), Mode = BindingMode.TwoWay }); var result = await _pointDialog.ShowAsync(); }
private async Task<Credential> DoSignInInUIThread(CredentialRequestInfo credentialRequestInfo) { var signInDialog = this; // Create the ContentDialog that contains the SignInDialog var contentDialog = new ContentDialog { SecondaryButtonText = "cancel", PrimaryButtonText = "sign in", FullSizeDesired = true, Content = signInDialog, }; contentDialog.PrimaryButtonClick += ContentDialogOnPrimaryButtonClick; // Bind the Title so the ContentDialog Title is the SignInDialog title (that will be initialized later) contentDialog.SetBinding(ContentDialog.TitleProperty, new Binding { Path = new PropertyPath("Title"), Source = signInDialog }); contentDialog.SetBinding(ContentDialog.IsPrimaryButtonEnabledProperty, new Binding { Path = new PropertyPath("IsReady"), Source = signInDialog }); contentDialog.Closed += ContentDialogOnClosed; // be sure the SignInDialog is deactivated when pressing back button // Show the content dialog var _ = contentDialog.ShowAsync(); // don't await else that would block here // Wait for the creation of the credential Credential crd; try { crd = await signInDialog.WaitForCredentialAsync(credentialRequestInfo); } finally { // Close the content dialog contentDialog.Hide(); } return crd; }
private void CopyBindings(ContentDialog dialog, DependencyProperty property, string path) { Contract.Requires(dialog != null, nameof(dialog)); Contract.Requires(property != null, nameof(property)); dialog.SetBinding(property, new Binding { Source = this, Path = new PropertyPath(path) }); }
private async void ButtonShowContentDialog4_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; // Creates the password box var passwordBox = new PasswordBox { IsPasswordRevealButtonEnabled = true, Margin = new Thickness(5) }; // Creates the StackPanel with the content var contentPanel = new StackPanel(); contentPanel.Children.Add(new TextBlock { Text = "Insert your password to access the application", Margin = new Thickness(5), TextWrapping = TextWrapping.WrapWholeWords }); contentPanel.Children.Add(passwordBox); // Creates the password dialog ContentDialog _passwordDialog = new ContentDialog { PrimaryButtonText = "Accept", IsPrimaryButtonEnabled = false, SecondaryButtonText = "Exit", Title = "Authentication", Content = contentPanel }; // Report that the dialog has been opened to avoid overlapping _passwordDialog.Opened += delegate { // HACK - opacity set to 0 to avoid seeing behind dialog Window.Current.Content.Opacity = 0; }; // Report that the dialog has been closed to enable it again _passwordDialog.Closed += delegate { // HACK - opacity set to 1 to reset the window to original options Window.Current.Content.Opacity = 1; }; // Clear inserted password for next logins _passwordDialog.PrimaryButtonClick += delegate { // ... login ... }; // Close the app if the user doesn't insert the password _passwordDialog.SecondaryButtonClick += delegate { Application.Current.Exit(); }; // Set the binding to enable/disable the accept button _passwordDialog.SetBinding(ContentDialog.IsPrimaryButtonEnabledProperty, new Binding { Source = passwordBox, Path = new PropertyPath("Password"), Mode = BindingMode.TwoWay }); var result = await _passwordDialog.ShowAsync(); btn.Content = "Result: " + result; }