public async void OnGameStartQuestions() { { var dialog = new MessageDialog("Would you like to play with real player or computer?", "Starting a new game"); var cmdOpt1 = new UICommand("player vs player", cmd => GameManager.SetPvP(), 1); var cmdOpt2 = new UICommand("player vs computer", cmd => GameManager.SetPvAI(), 2); dialog.Commands.Add(cmdOpt1); dialog.Commands.Add(cmdOpt2); dialog.DefaultCommandIndex = 0; await dialog.ShowAsync(); } if (GameManager.IsGameVersusAI) { var dialog = new MessageDialog("Select the color of your pieces.\n(Darker coloured pieces moves first)", "Color"); var cmdOpt1 = new UICommand("dark", cmd => GameManager.SetPlayerBlack(), 1); var cmdOpt2 = new UICommand("light", cmd => GameManager.SetPlayerWhite(), 2); dialog.Commands.Add(cmdOpt1); dialog.Commands.Add(cmdOpt2); dialog.DefaultCommandIndex = 0; await dialog.ShowAsync(); } GameManager.Start(); }
public virtual void ShowMessage(string title, UICommand alternative1) { var messageDialog = new MessageDialog(title); messageDialog.Commands.Add(alternative1); messageDialog.CancelCommandIndex = 0; messageDialog.ShowAsync(); }
private async void OnTapped(object sender, TappedRoutedEventArgs e) { TextBlock tb = sender as TextBlock; PopupMenu menu = new PopupMenu(); UICommandInvokedHandler invokedHandler = (cmd) => { SolidColorBrush brush = cmd.Id as SolidColorBrush; tb.Foreground = brush; }; UICommand cmdRed = new UICommand("红", invokedHandler, new SolidColorBrush(Colors.Red)); UICommand cmdOrange = new UICommand("橙", invokedHandler, new SolidColorBrush(Colors.Orange)); UICommand cmdPurple = new UICommand("紫", invokedHandler, new SolidColorBrush(Colors.Purple)); menu.Commands.Add(cmdRed); menu.Commands.Add(cmdOrange); menu.Commands.Add(cmdPurple); GeneralTransform gt = tb.TransformToVisual(null); Point popupPoint = gt.TransformPoint(new Point(0d, tb.ActualHeight)); await menu.ShowAsync(popupPoint); }
private async void b_back_Click(object sender, RoutedEventArgs e) { var title = "Create Event"; var content = "Your changes won't be saved if you access another view of the application! "; var dialog = new MessageDialog(content, title); var yesComand = new Windows.UI.Popups.UICommand("Ok") { Id = 0 }; var noCommand = new Windows.UI.Popups.UICommand("Cancel") { Id = 1 }; dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 0; dialog.Commands.Add(yesComand); dialog.Commands.Add(noCommand); var result = await dialog.ShowAsync(); if (result == yesComand) { Frame?.Navigate(typeof(MainPage)); } else { sv_Menu.IsPaneOpen = !sv_Menu.IsPaneOpen; } }
public async virtual Task Notify(string message, string title, string primaryOptionText, string secondaryOptionText, Action primaryOptionAction = null, Action secondaryOptionAction = null) { if(Application.Current.Resources.ContainsKey(message)) message = (string) Application.Current.Resources[message]; if(Application.Current.Resources.ContainsKey(title)) title = (string) Application.Current.Resources[title]; var dialog = new MessageDialog(message, title); if (!string.IsNullOrEmpty(primaryOptionText)) { primaryOptionText = (string) Application.Current.Resources[primaryOptionText]; var command = new UICommand(primaryOptionText); if (primaryOptionAction != null) command.Invoked = uiCommand => primaryOptionAction(); dialog.Commands.Add(command); } if (!string.IsNullOrEmpty(secondaryOptionText)) { secondaryOptionText = (string)Application.Current.Resources[secondaryOptionText]; var command = new UICommand(secondaryOptionText); if (secondaryOptionAction != null) command.Invoked = uiCommand => secondaryOptionAction(); dialog.Commands.Add(command); } await dialog.ShowAsync(); }
private async void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e) { //获取当前的激活的窗口的框架 Frame frame = Window.Current.Content as Frame; //判断是否为空,是否能返回,其实就是主页面了,主页面肯定不能返回嘛 if (null != frame && (!frame.CanGoBack)) { //设置事件已经处理 e.Handled = true; //设置在最后一个界面跳出弹出窗口 var messageDig = new MessageDialog("确定退出吗?"); var btn_OK = new UICommand("确定"); var btn_NO = new UICommand("取消"); messageDig.Commands.Add(btn_OK); messageDig.Commands.Add(btn_NO); //展示窗口,获取按钮是否退出 var result = await messageDig.ShowAsync(); //如果是确定退出就直接让应用程序退出 if (null != result && result.Label == "确定") { Application.Current.Exit(); } } //如果可以返回,就返回上一个界面 else if (frame.CanGoBack) { frame.GoBack(); e.Handled = true; } }
public void validateName(object sender, RoutedEventArgs e) { // Check to make sure the name isn't blank or already used then change to first button to train screen device_name = device_name_text.Text; DeviceManager m = ((App)(CPRemoteApp.App.Current)).deviceController; if(device_name.TrimStart(' ').Length == 0) { MessageDialog msgDialog = new MessageDialog("Please enter a valid name for the device! The device's name cannot be empty!", "Whoops!"); UICommand okBtn = new UICommand("OK"); okBtn.Invoked += delegate { }; msgDialog.Commands.Add(okBtn); msgDialog.ShowAsync(); return; } else if (channel_or_volume) { foreach (VolumeDevice d in m.getVolumeDevices()) { if (d.get_name() == device_name) { MessageDialog msgDialog = new MessageDialog("There is already a volume device saved with that name! Please enter a unique name for the device!", "Whoops!"); UICommand okBtn = new UICommand("OK"); okBtn.Invoked += delegate { }; msgDialog.Commands.Add(okBtn); msgDialog.ShowAsync(); return; } } } else { foreach (ChannelDevice d in m.getChannelDevices()) { if (d.get_name() == device_name) { MessageDialog msgDialog = new MessageDialog("There is already a channel device saved with that name! Please enter a unique name for the device!", "Whoops!"); UICommand okBtn = new UICommand("OK"); okBtn.Invoked += delegate { }; msgDialog.Commands.Add(okBtn); msgDialog.ShowAsync(); return; } } } device_name_text.Visibility = Windows.UI.Xaml.Visibility.Collapsed; device_name_block.Visibility = Windows.UI.Xaml.Visibility.Collapsed; next_button.Visibility = Windows.UI.Xaml.Visibility.Collapsed; if (channel_or_volume) { trainVolumeDevice(); } else { // Start at train Zero and Populate all of the IR information, via next button clicks trainZero(); } }
public async Task<bool> RunAsync() { Telemetry.Client.TrackTrace("Startup Workflow - Begin"); var authenticatedSilently = await SecurityManager.TryAuthenticateSilently(); if (!authenticatedSilently) { Telemetry.Client.TrackTrace("Startup Workflow - Authentication required."); if (!frame.Navigate(typeof(LoginPage), arguments)) { throw new Exception("Failed to create login page"); } bool authenticated = false; while (!authenticated) { authenticated = await SecurityManager.Authenticate(); if (!authenticated) { Telemetry.Client.TrackTrace("Startup Workflow - Authentication failed. Asking user to retry."); var resourceManager = CompositionManager.Current.GetInstance<IStringResourceManager>(); var messageTitle = resourceManager.GetString("LoginRequiredMessageTitle"); var messageText = resourceManager.GetString("LoginRequiredMessageText"); var dialog = new MessageDialog(messageText, messageTitle); var okCommand = new UICommand(resourceManager.GetString("LoginFailedRetry")); var cancelCommand = new UICommand(resourceManager.GetString("LoginFailedCancelAndExit")); dialog.Commands.Add(okCommand); dialog.Commands.Add(cancelCommand); var dialogResult = await dialog.ShowAsync(); if (dialogResult == cancelCommand) { Telemetry.Client.TrackTrace("Startup Workflow - Authentication failed. User declined to retry.", TelemetrySeverityLevel.Warning); return false; } } } } Telemetry.Client.TrackTrace("Startup Workflow - Authentication successful. Redirecting to the main page."); if (!frame.Navigate(typeof(MainPage), arguments)) { throw new Exception("Failed to create initial page"); } return true; }
private async void showExitConfirmation() { var msg = new MessageDialog(EXIT_CONFIRMATION_TEXT, EXIT_CONFIRMATION_TITLE); var okBtn = new UICommand("Exit", new UICommandInvokedHandler(ConfirmationCommandHandler)); var cancelBtn = new UICommand("Cancel", new UICommandInvokedHandler(ConfirmationCommandHandler)); msg.Commands.Add(okBtn); msg.Commands.Add(cancelBtn); IUICommand result = await msg.ShowAsync(); }
private void ShowError(Exception exception) { UICommand okCommand = new UICommand("OK", (cmd) => { Messenger.Default.Send<StartNewGameMessage>(new StartNewGameMessage()); }, 1); ShowMessage("Error loading game", exception.Message, new UICommand[] { okCommand }); }
private async void showSaveConfirmation() { var msg = new MessageDialog(SAVE_CONFIRMATION_TEXT, SAVE_CONFIRMATION_TITLE); var okBtn = new UICommand(FINISH, new UICommandInvokedHandler(SaveConfirmationCommandHandler)); var cancelBtn = new UICommand(CANCEL, new UICommandInvokedHandler(SaveConfirmationCommandHandler)); msg.Commands.Add(okBtn); msg.Commands.Add(cancelBtn); IUICommand result = await msg.ShowAsync(); }
private async void OnClick(object sender, RoutedEventArgs e) { MessageDialog dlg = new MessageDialog("确定要执行任务吗", "提示"); UICommand cmdok = new UICommand("确定", new UICommandInvokedHandler(OnCommandAct), 1); UICommand cmdcancel = new UICommand("取消", new UICommandInvokedHandler(OnCommandAct), 2); dlg.Commands.Add(cmdok); dlg.Commands.Add(cmdcancel); await dlg.ShowAsync(); }
public virtual void ShowMessage(string title, string content, UICommand alternative1, UICommand alternative2) { var messageDialog = new MessageDialog(content, title); messageDialog.Commands.Add(alternative1); messageDialog.Commands.Add(alternative2); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 1; messageDialog.ShowAsync(); }
public async Task <bool> AskYesOrNoAsync(string message, string title) { Windows.UI.Popups.UICommand yesCommand = new Windows.UI.Popups.UICommand(); yesCommand.Label = "Yes"; Windows.UI.Popups.UICommand noCommand = new Windows.UI.Popups.UICommand(); noCommand.Label = "No"; return(await AskYesOrNoAsync(message, title, yesCommand, noCommand) == yesCommand); }
/// <summary> /// Adds a button to the MessageDialog with given caption and action. /// </summary> /// <param name="dialog"></param> /// <param name="caption"></param> /// <param name="action"></param> public static void AddButton(this MessageDialog dialog, string caption, Action action) { var cmd = new UICommand( caption, c => { if (action != null) action.Invoke(); }); dialog.Commands.Add(cmd); }
private async void ShowMessage(string title, string content, UICommand[] commands) { var dialog = new MessageDialog(content, title); foreach (var command in commands) { dialog.Commands.Add(command); } await dialog.ShowAsync(); }
/// <summary> /// 添加一个命令到对话框。 /// </summary> /// <param name="dialog">对话框。</param> /// <param name="label">命令文本。</param> /// <param name="action">命令动作。</param> /// <returns>对话框。</returns> /// <exception cref="ArgumentNullException"><c>dialog</c> 为空。</exception> public static MessageDialog AddCommand(this MessageDialog dialog, string label, Action action) { if (dialog == null) { throw new ArgumentNullException(nameof(dialog)); } UICommand command = new UICommand(label, commandAction => action?.Invoke()); dialog.Commands.Add(command); return dialog; }
private async void btnGenerate_Click(object sender, RoutedEventArgs e) { MessageDialog msgDialog = new MessageDialog("Game Type", "Please select game type"); UICommand sixBtn = new UICommand("Lotto Or Lotto Plus"); sixBtn.Invoked = sixBtnClick; msgDialog.Commands.Add(sixBtn); UICommand powerBtn = new UICommand("Powerball"); powerBtn.Invoked = powerBtnClick; msgDialog.Commands.Add(powerBtn); await msgDialog.ShowAsync(); }
/// <summary> /// Prompts the user to install the Media Feature Pack. /// </summary> /// <returns>An awaitable task that returns when the prompt has completed.</returns> public static async Task PromptForMediaPack() { var messageDialog = new MessageDialog(MediaPlayer.GetResourceString("MediaFeaturePackRequiredLabel"), MediaPlayer.GetResourceString("MediaFeaturePackRequiredText")); var cmdDownload = new UICommand(MediaPlayer.GetResourceString("MediaFeaturePackDownloadLabel")); var cmdCancel = new UICommand(MediaPlayer.GetResourceString("MediaFeaturePackCancelLabel")); messageDialog.Commands.Add(cmdDownload); messageDialog.Commands.Add(cmdCancel); var cmd = await messageDialog.ShowAsync(); if (cmd == cmdDownload) { await Launcher.LaunchUriAsync(MediaPackUri); } }
private async void OnExportSelectedToExcel(object sender, RoutedEventArgs e) { ExcelEngine excelEngine = new ExcelEngine(); var workBook = excelEngine.Excel.Workbooks.Create(); workBook.Version = ExcelVersion.Excel2010; workBook.Worksheets.Create(); if ((bool)this.customizeSelectedRow.IsChecked) { this.sfDataGrid.ExportToExcel(this.sfDataGrid.SelectedItems, new ExcelExportingOptions() { CellsExportingEventHandler = CellExportingHandler, ExportingEventHandler = CustomizedexportingHandler }, workBook.Worksheets[0]); } else { this.sfDataGrid.ExportToExcel(this.sfDataGrid.SelectedItems, new ExcelExportingOptions() { CellsExportingEventHandler = CellExportingHandler, ExportingEventHandler = exportingHandler }, workBook.Worksheets[0]); } workBook = excelEngine.Excel.Workbooks[0]; var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.Desktop, SuggestedFileName = "Sample" }; if (workBook.Version == ExcelVersion.Excel97to2003) { savePicker.FileTypeChoices.Add("Excel File (.xls)", new List<string>() { ".xls" }); } else { savePicker.FileTypeChoices.Add("Excel File (.xlsx)", new List<string>() { ".xlsx" }); } var storageFile = await savePicker.PickSaveFileAsync(); if (storageFile != null) { await workBook.SaveAsAsync(storageFile); var msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); var yesCmd = new UICommand("Yes"); var noCmd = new UICommand("No"); msgDialog.Commands.Add(yesCmd); msgDialog.Commands.Add(noCmd); var cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } } excelEngine.Dispose(); }
private void ShowVictory() { UICommand newCommand = new UICommand("Start New Game", (cmd) => { Messenger.Default.Send<StartNewGameMessage>(new StartNewGameMessage()); }, 1); UICommand exitCommand = new UICommand("Exit Game", (cmd) => { App.Current.Exit(); }, 2); ShowMessage("You Won!", "Would you like to play again?", new UICommand[] { newCommand, exitCommand }); }
protected async override void OnFileActivated(FileActivatedEventArgs e) { System.Diagnostics.Debug.WriteLine("App started."); HelperMethods.clearTempFiles(); //Startup stuff #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } // Ensure the current window is active Window.Current.Activate(); System.Diagnostics.Debug.WriteLine("App goes to correct path."); Windows.Storage.IStorageItem file = e.Files.First(); Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("passFileToken", file); MessageDialog msgbox = new MessageDialog("Would you like to add this item to your wallet?", "Importing .PKPASS file!"); UICommand uiYes = new UICommand("Yes"); UICommand uiNo = new UICommand("No"); msgbox.Commands.Add(uiYes); msgbox.Commands.Add(uiNo); msgbox.DefaultCommandIndex = 0; msgbox.CancelCommandIndex = 1; if (await msgbox.ShowAsync() == uiYes) rootFrame.Navigate(typeof(PassProcessor), "fileToken"); else rootFrame.Navigate(typeof(MainPage)); }
public async Task<bool> ShowConfirmation(string title, string message, string okCommandText = null, string cancelCommandText = null) { Guard.NotNullOrEmpty(title, nameof(title)); Guard.NotNullOrEmpty(message, nameof(message)); var dialog = new MessageDialog(message, title); var okCommand = new UICommand(okCommandText ?? resourceManager.GetString(ConfirmationOkButtonTextKey, "RES_MISSING OK")); dialog.Commands.Add(okCommand); dialog.Commands.Add(new UICommand(cancelCommandText ?? resourceManager.GetString(ConfirmationCancelButtonTextKey, "RES_MISSING Cancel"))); var resultCommand = await dialog.ShowAsync(); return resultCommand == okCommand; }
private async void importKB2calendarButton_Click(object sender, RoutedEventArgs e) { var dig = new MessageDialog("订阅课表为实验室功能,我们无法保证此功能100%可用与数据100%正确性,我们期待您的反馈。\n\n是否继续尝试?", "警告"); var btnOk = new UICommand("是"); dig.Commands.Add(btnOk); var btnCancel = new UICommand("否"); dig.Commands.Add(btnCancel); var result = await dig.ShowAsync(); if (null != result && result.Label == "是") { Frame.Navigate(typeof(ImportKB2CalendarPage)); } else if (null != result && result.Label == "否") { } }
public async void HandleException(string userFriendlyMessage, Exception ex) { if (ErrorService.exceptionHandled) { return; } MessageDialog messageDialog = new MessageDialog("An error has occurred :" + userFriendlyMessage, "Error occured"); UICommand item = new UICommand("Close", delegate(IUICommand e) { ErrorService.exceptionHandled = false; } ); messageDialog.Commands.Add(item); await messageDialog.ShowAsync(); ErrorService.exceptionHandled = true; }
private async void OnPdfExportDataGrid(object sender, RoutedEventArgs e) { cellstyle = new PdfGridCellStyle(); cellstyle.StringFormat = new PdfStringFormat() { Alignment = PdfTextAlignment.Right }; cellstyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 9f, PdfFontStyle.Regular); cellstyle.Borders.All = new PdfPen(PdfBrushes.DarkGray, 0.2f); var options = new PdfExportingOptions() { AutoColumnWidth = (bool)this.ColumnWidth.IsChecked, AutoRowHeight = (bool)this.RowHeight.IsChecked, ExportGroups = (bool)this.ExportGroup.IsChecked, ExportGroupSummary = (bool)this.ExportGroupSummary.IsChecked, ExportTableSummary = (bool)this.ExportTableSummary.IsChecked, RepeatHeaders = (bool)this.RepeatHeader.IsChecked, FitAllColumnsInOnePage = (bool)this.FitAllColumns.IsChecked, ExportingEventHandler = GridPdfExportingEventhandler, CellsExportingEventHandler = GridCellPdfExportingEventhandler, PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler }; var pdfDocument = this.sfDataGrid.ExportToPdf(this.sfDataGrid.SelectedItems, options); pdfDocument.PageSettings.Margins.Top = -34f; pdfDocument.PageSettings.Margins.Bottom = -30f; var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.Desktop, SuggestedFileName = "Sample" }; savePicker.FileTypeChoices.Add("Pdf Files(.pdf)", new List<string>() { ".pdf" }); var storageFile = await savePicker.PickSaveFileAsync(); if (storageFile != null) { await pdfDocument.SaveAsync(storageFile); var msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); var yesCmd = new UICommand("Yes"); var noCmd = new UICommand("No"); msgDialog.Commands.Add(yesCmd); msgDialog.Commands.Add(noCmd); var cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } } }
async void DisplayError(string problem, string message) { string content = "Problem: " + problem + System.Environment.NewLine + "Message: " + message; MessageDialog dialog = new MessageDialog( content, "OAuth Authentication failed..."); UICommand cmdOk = new UICommand("OK"); dialog.Commands.Add(cmdOk); await dialog.ShowAsync(); }
private async void btnResults_Click(object sender, RoutedEventArgs e) { MessageDialog msgDialog = new MessageDialog("Game Type", "Please select game type"); UICommand lottoBtn = new UICommand("Lotto"); lottoBtn.Invoked = lottoBtnClick; msgDialog.Commands.Add(lottoBtn); UICommand lottoPlusBtn = new UICommand("Lotto Plus"); lottoPlusBtn.Invoked = lottoPlusBtnClick; msgDialog.Commands.Add(lottoPlusBtn); UICommand powerballBtn = new UICommand("Powerball"); powerballBtn.Invoked = powerballBtnClick; msgDialog.Commands.Add(powerballBtn); await msgDialog.ShowAsync(); }
private async void messageBox(string msg) { MessageDialog msgDialog = new MessageDialog(msg); //Replay Button UICommand replayBtn = new UICommand("Replay"); replayBtn.Invoked = replayBtnClick; msgDialog.Commands.Add(replayBtn); //Exit Button UICommand exitBtn = new UICommand("Exit"); exitBtn.Invoked = ExitBtnClick; msgDialog.Commands.Add(exitBtn); //Show message await msgDialog.ShowAsync(); }
/// <summary> /// 连接请求事件处理 /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args) { //使用UI线程弹出连接请求的接收和拒绝弹窗 await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { MessageDialog md = new MessageDialog("是否接收" + args.PeerInformation.DisplayName + "连接请求", "蓝牙连接"); UICommand yes = new UICommand("接收"); UICommand no = new UICommand("拒绝"); md.Commands.Add(yes); md.Commands.Add(no); var result = await md.ShowAsync(); if (result == yes) { ConnectToPeer(args.PeerInformation); } }); }
private async void NewGameButton_OnClick(object sender, RoutedEventArgs e) { _shouldStartNewGame = false; var dialog = new MessageDialog("Are you sure you want to end this game and start a new one?", "New Game?"); var cmdNo = new UICommand("No", cmd => _shouldStartNewGame = false, 1); var cmdYes = new UICommand("Yes", cmd => _shouldStartNewGame = true, 2); dialog.Commands.Add(cmdNo); dialog.Commands.Add(cmdYes); dialog.DefaultCommandIndex = 0; await dialog.ShowAsync(); if (_shouldStartNewGame) OnGameStartQuestions(); }
private async void ClearBtn_Click(object sender, RoutedEventArgs e) { var msg = new MessageDialog("This will clear all of your data, confirm?", "Confirm Clear"); var okBtn = new UICommand("OK"); var cancelBtn = new UICommand("Cancel"); msg.Commands.Add(okBtn); msg.Commands.Add(cancelBtn); IUICommand result = await msg.ShowAsync(); if (result != null && result.Label == "OK") { viewModel.ClearData(); HistoryList.ItemsSource = null; NametxtBox.Text = ""; PricetxtBox.Text = ""; } }
// This is the default setup to show location consent message box to the user // You can customize it to your needs, but do not remove it completely if your application // uses location services, as it is a requirement in Windows Store certification process private async void SetupLocationService() { AppCallbacks appCallbacks = AppCallbacks.Instance; if (!appCallbacks.IsLocationCapabilitySet()) { return; } const string settingName = "LocationContent"; bool userGaveConsent = false; object consent; var settings = Windows.Storage.ApplicationData.Current.LocalSettings; var userWasAskedBefore = settings.Values.TryGetValue(settingName, out consent); if (!userWasAskedBefore) { var messageDialog = new Windows.UI.Popups.MessageDialog("Can this application use your location?", "Location services"); var acceptCommand = new Windows.UI.Popups.UICommand("Yes"); var declineCommand = new Windows.UI.Popups.UICommand("No"); messageDialog.Commands.Add(acceptCommand); messageDialog.Commands.Add(declineCommand); userGaveConsent = (await messageDialog.ShowAsync()) == acceptCommand; settings.Values.Add(settingName, userGaveConsent); } else { userGaveConsent = (bool)consent; } if (userGaveConsent) { // Must be called from UI thread appCallbacks.SetupGeolocator(); } }
private static async void _initializationFailedNotification(Exception ex) { Telemetry.TrackException(ex, GetAppContext()); try { MessageDialog dialog = new Windows.UI.Popups.MessageDialog(ex.Message, "Initialization error"); UICommand uiCommand = new Windows.UI.Popups.UICommand("OK") { Id = 0 }; dialog.Commands.Add(uiCommand); dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 0; IUICommand result = await dialog.ShowAsync(); } finally { Application.Current.Exit(); //CoreApplication.Exit(); } }