public async Task <StorageFolder> SaveProject(StorageFolder storageFolder, List <InkStrokeContainer> strokes, ProjectMetaData metaData, List <CanvasComponent> components) { //Use existing folder if (storageFolder != null) { //Save the strokes drawn, the project metadata so the current state of the eapplication is saved, and the shapes SaveStrokes(storageFolder, strokes); SaveMetaData(metaData, storageFolder); SaveCanvasComponents(components, storageFolder); return(storageFolder); } //Create new folder to save files SaveDialog save = new SaveDialog(); await save.ShowAsync(); if (save.result == ContentDialogResult.Primary) { //Store the chosen folder so it is automatically saved to the location specified in the future storageFolder = save.folder; SaveStrokes(storageFolder, strokes); SaveMetaData(metaData, storageFolder); SaveCanvasComponents(components, storageFolder); return(storageFolder); } return(null); }
public async Task OpenDialogAsync(DialogToNavigate dialogToNavigate, UserOptions userOptions = null) { if (dialogToNavigate == DialogToNavigate.Setup) { await AppLocator.SetupViewModel.Initialize(); SetupDialog setupDialog = new SetupDialog(); setupDialog.DataContext = AppLocator.SetupViewModel; await setupDialog.ShowAsync(); } else { if (userOptions == null) { userOptions = new UserOptions(); } await AppLocator.SaveViewModel.Initialize(); SaveDialog saveDialog = new SaveDialog(); var saveVM = AppLocator.SaveViewModel; saveVM.UserOptions = userOptions; saveDialog.DataContext = saveVM; await saveDialog.ShowAsync(); } }
public async void Execute(object parameter) { SaveDialog saveDialog = new SaveDialog(); ContentDialogResult result = await saveDialog.ShowAsync(); // Creates an error message and returns. if (result != ContentDialogResult.Primary) { new ContentDialog() { Title = "Cancelled Creation.", PrimaryButtonText = "Okay." }; return; } TextBox box = (TextBox)parameter; Models.NoteModel newNote = new Models.NoteModel(saveDialog.NoteTitle, box.Text); // Trys to save the new note to the file system. try { Repository.NotesRepo.SaveNotesToFile(newNote); } catch (Exception) { Debug.WriteLine("Error saving new note to folder."); return; } // Adds note to the list, changes the selected node, and refreshes the list visually. notesViewModel.AllNotes.Add(newNote); notesViewModel.SelectedNote = newNote; notesViewModel.FilterNotes(); new ContentDialog() { Title = "Saved Note Sucessfully.", PrimaryButtonText = "Okay." }; }
private async void ToggleButton_Checked(object sender, RoutedEventArgs e) { var button = (ToggleButton)sender; // Get our encoder properties var frameRateItem = (FrameRateItem)FrameRateComboBox.SelectedItem; var resolutionItem = (ResolutionItem)ResolutionComboBox.SelectedItem; var bitrateItem = (BitrateItem)BitrateComboBox.SelectedItem; if (UseCaptureItemToggleSwitch.IsOn) { resolutionItem.IsZero(); } var width = resolutionItem.Resolution.Width; var height = resolutionItem.Resolution.Height; var bitrate = bitrateItem.Bitrate; var frameRate = frameRateItem.FrameRate; if (UseCaptureItemToggleSwitch.IsOn) { resolutionItem.IsZero(); } // Get our capture item var picker = new GraphicsCapturePicker(); var item = await picker.PickSingleItemAsync(); if (item == null) { button.IsChecked = false; return; } // Use the capture item's size for the encoding if desired if (UseCaptureItemToggleSwitch.IsOn) { width = (uint)item.Size.Width; height = (uint)item.Size.Height; // Even if we're using the capture item's real size, // we still want to make sure the numbers are even. // Some encoders get mad if you give them odd numbers. width = EnsureEven(width); height = EnsureEven(height); } // Put videos in the temp folder var tempFile = await GetTempFileAsync(); _tempFile = tempFile; // Tell the user we've started recording var visual = ElementCompositionPreview.GetElementVisual(Ellipse); var animation = visual.Compositor.CreateScalarKeyFrameAnimation(); animation.InsertKeyFrame(0, 1); animation.InsertKeyFrame(1, 0); animation.Duration = TimeSpan.FromMilliseconds(1500); animation.IterationBehavior = AnimationIterationBehavior.Forever; visual.StartAnimation("Opacity", animation); RecordIcon.Visibility = Visibility.Collapsed; StopIcon.Visibility = Visibility.Visible; Ellipse.Visibility = Visibility.Visible; ToolTip toolTip = new ToolTip(); toolTip.Content = "Stop recording"; ToolTipService.SetToolTip(MainButton, toolTip); AutomationProperties.SetName(MainButton, "Stop recording"); MainTextBlock.Text = "recording..."; var originalBrush = MainTextBlock.Foreground; MainTextBlock.Foreground = new SolidColorBrush(Colors.Red); // Kick off the encoding try { using (var stream = await tempFile.OpenAsync(FileAccessMode.ReadWrite)) using (_encoder = new Encoder(_device, item)) { var encodesuccess = await _encoder.EncodeAsync( stream, width, height, bitrate, frameRate); if (encodesuccess == false) { ContentDialog errorDialog = new ContentDialog { Title = "Recording failed", Content = "Windows cannot encode your video", CloseButtonText = "OK" }; await errorDialog.ShowAsync(); } } MainTextBlock.Foreground = originalBrush; } catch (Exception ex) { Crashes.TrackError(ex); Debug.WriteLine(ex.Message); Debug.WriteLine(ex); var message = GetMessageForHResult(ex.HResult); if (message == null) { message = $"Whoops, something went wrong!\n0x{ex.HResult:X8} - {ex.Message}"; } ContentDialog errorDialog = new ContentDialog { Title = "Recording failed", Content = message, CloseButtonText = "OK" }; await errorDialog.ShowAsync(); button.IsChecked = false; visual.StopAnimation("Opacity"); Ellipse.Visibility = Visibility.Collapsed; MainTextBlock.Text = "failure"; MainTextBlock.Foreground = originalBrush; RecordIcon.Visibility = Visibility.Visible; StopIcon.Visibility = Visibility.Collapsed; toolTip.Content = "Start recording"; ToolTipService.SetToolTip(MainButton, toolTip); AutomationProperties.SetName(MainButton, "Start recording"); await _tempFile.DeleteAsync(); return; } // At this point the encoding has finished, // tell the user we're now saving MainButton.IsChecked = false; MainTextBlock.Text = ""; visual.StopAnimation("Opacity"); Ellipse.Visibility = Visibility.Collapsed; RecordIcon.Visibility = Visibility.Visible; StopIcon.Visibility = Visibility.Collapsed; ToolTip newtoolTip = new ToolTip(); toolTip.Content = "Start recording"; ToolTipService.SetToolTip(MainButton, toolTip); AutomationProperties.SetName(MainButton, "Start recording"); if (PreviewToggleSwitch.IsOn) { CoreApplicationView newView = CoreApplication.CreateNewView(); int newViewId = 0; await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { var preview = new VideoPreviewPage(_tempFile); ApplicationViewTitleBar formattableTitleBar = ApplicationView.GetForCurrentView().TitleBar; formattableTitleBar.ButtonBackgroundColor = Colors.Transparent; CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.ExtendViewIntoTitleBar = true; Window.Current.Content = preview; Window.Current.Activate(); newViewId = ApplicationView.GetForCurrentView().Id; }); bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId); } else { ContentDialog dialog = new SaveDialog(_tempFile); await dialog.ShowAsync(); } }
} = new Setting(); //Store all app setting here.. public MainPage() { InitializeComponent(); //extent app in to the title bar CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true; ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; titleBar.ButtonBackgroundColor = Colors.Transparent; titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; //Subscribe to events QSetting.afterThemeChanged += UpdateUIAccordingToNewTheme; UpdateUIAccordingToNewTheme(QSetting.Theme); QSetting.afterFontSizeChanged += UpdateText1FontSize; QSetting.afterAutoSaveChanged += UpdateAutoSave; // CreateItems(); LoadSettings(); LoadFonts(); VersionNumber.Text = string.Format(textResource.GetString("VersionFormat"), Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor, Package.Current.Id.Version.Build, Package.Current.Id.Version.Revision); //check if focus is on app or off the app Window.Current.CoreWindow.Activated += (sender, args) => { if (args.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated) { CommandBar2.Focus(FocusState.Programmatic); // Set focus off the main content } }; //ask user if they want to save before closing the app Windows.UI.Core.Preview.SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += async(sender, e) => { var deferral = e.GetDeferral(); if (!Changed) { //No change made, either new document or file saved deferral.Complete(); } //close dialogs so the app does not hang SaveDialog.Hide(); Settings.Hide(); await SaveDialog.ShowAsync(); if (SaveDialogValue != DialogResult.Cancel) { deferral.Complete(); } if (SaveDialogValue == DialogResult.Cancel) { e.Handled = true; deferral.Complete(); } SaveDialogValue = DialogResult.None; //reset save dialog }; CheckPushNotifications(); //check for push notifications this.Loaded += MainPage_Loaded; this.LayoutUpdated += MainPage_LayoutUpdated; }
private async void SaveSoftwareBitmapToFile(SoftwareBitmap softwareBitmap, StorageFile outputFile) { Guid?encoderType = FileTypeExtensionToBitmapEncoder(outputFile.FileType); if (encoderType == null) { return; } using (IRandomAccessStream stream = await outputFile.OpenAsync(FileAccessMode.ReadWrite)) { BitmapEncoder encoder = null; bool?jpegx = false; if (encoderType != BitmapEncoder.JpegEncoderId && encoderType != BitmapEncoder.JpegXREncoderId) { jpegx = null; } else if (encoderType == BitmapEncoder.JpegEncoderId) { jpegx = false; } else if (encoderType == BitmapEncoder.JpegXREncoderId) { jpegx = true; } SaveDialog dialog = new SaveDialog(jpegx); ContentDialogResult result = await dialog.ShowAsync(); if (encoderType == BitmapEncoder.JpegEncoderId || encoderType == BitmapEncoder.JpegXREncoderId) { if (result == ContentDialogResult.Secondary) { var propertySet = new BitmapPropertySet(); propertySet.Add("ImageQuality", new BitmapTypedValue(dialog.Quality, Windows.Foundation.PropertyType.Single)); if (encoderType == BitmapEncoder.JpegXREncoderId) { propertySet.Add("Lossless", new BitmapTypedValue(dialog.Lossless, Windows.Foundation.PropertyType.Boolean)); } encoder = await BitmapEncoder.CreateAsync((Guid)encoderType, stream, propertySet); } else { return; } } else { // Create an encoder with the desired format encoder = await BitmapEncoder.CreateAsync((Guid)encoderType, stream); } // Set the software bitmap encoder.SetSoftwareBitmap(softwareBitmap); // Set additional encoding parameters, if needed //encoder.BitmapTransform.ScaledWidth = 320; //encoder.BitmapTransform.ScaledHeight = 240; //encoder.BitmapTransform.Rotation = Windows.Graphics.Imaging.BitmapRotation.Clockwise90Degrees; encoder.BitmapTransform.InterpolationMode = dialog.Interpolation; encoder.IsThumbnailGenerated = true; try { await encoder.FlushAsync(); } catch (Exception err) { const int WINCODEC_ERR_UNSUPPORTEDOPERATION = unchecked ((int)0x88982F81); switch (err.HResult) { case WINCODEC_ERR_UNSUPPORTEDOPERATION: // If the encoder does not support writing a thumbnail, then try again // but disable thumbnail generation. encoder.IsThumbnailGenerated = false; break; default: throw; } } if (encoder.IsThumbnailGenerated == false) { await encoder.FlushAsync(); } } }