private void AddPhoto(object sender, RoutedEventArgs e) { var ofd = new Microsoft.Win32.OpenFileDialog() { Filter = "JPG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|GIF Files (*.gif)|*.gif" }; var result = ofd.ShowDialog(); if (result == false) { return; } ImageFile item = new ImageFile(ofd.FileName); item.AddToCache(); Photos.Init(PhotosFolder.Current); }
private void WindowLoaded(object sender, EventArgs e) { var layer = AdornerLayer.GetAdornerLayer(CurrentPhoto); _cropSelector = new RubberbandAdorner(CurrentPhoto) { Window = this }; layer.Add(_cropSelector); #if VISUALCHILD CropSelector.Rubberband.Visibility = Visibility.Hidden; #endif #if NoVISUALCHILD CropSelector.ShowRect = false; #endif Photos = (PhotoList)(this.Resources["Photos"] as ObjectDataProvider)?.Data; Photos.Init(PhotosFolder.Current); ShoppingCart = (PrintList)(this.Resources["ShoppingCart"] as ObjectDataProvider)?.Data; }
private void WindowLoaded(object sender, EventArgs e) { if (ExecutionMode.IsRunningWithIdentity()) { this.Title = "PhotoStore"; this.TitleSpan.Foreground = Brushes.Blue; } else { this.Title = "Desktop App"; this.TitleSpan.Foreground = Brushes.Navy; } var layer = AdornerLayer.GetAdornerLayer(CurrentPhoto); _cropSelector = new RubberbandAdorner(CurrentPhoto) { Window = this }; layer.Add(_cropSelector); #if VISUALCHILD CropSelector.Rubberband.Visibility = Visibility.Hidden; #endif #if NoVISUALCHILD CropSelector.ShowRect = false; #endif Photos = (PhotoList)(this.Resources["Photos"] as ObjectDataProvider)?.Data; Photos.Init(PhotosFolder.Current); ShoppingCart = (PrintList)(this.Resources["ShoppingCart"] as ObjectDataProvider)?.Data; // listen for files being created via Share UX FileSystemWatcher watcher = new FileSystemWatcher(PhotosFolder.Current); watcher.EnableRaisingEvents = true; watcher.Created += Watcher_Created; }
private void WindowLoaded(object sender, EventArgs e) { //Please refer to the following blogpost to learn how you can use the method "IsRunningAsUWP" to detect whether or not you are running as a packged app or not: //https://blogs.msdn.microsoft.com/appconsult/2016/11/03/desktop-bridge-identify-the-applications-context/ if (ExecutionMode.IsRunningAsUwp()) { this.Title = "Desktop Bridge App: PhotoStore --- (Windows App Package)"; this.TitleSpan.Foreground = Brushes.Blue; //Detect if the previous version of the Desktop App is installed //The location of the uninstaller in the registry depends on the app's architecture and installer technology. This is different for every app. String uninstallString = (String)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{7AD02FB8-B85E-44BC-8998-F4803BA5A0E3}\", "UninstallString", null); //Detect if there is previous user data //In this example, the previous user data lives under the "unpackaged" local app data location String sourceDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PreviousPhotoStore"; bool isDataToMigrate = false; if (Directory.Exists(sourceDir)) { var list = Directory.EnumerateFiles(sourceDir); if (list.Count() == 0) { isDataToMigrate = false; } else { isDataToMigrate = true; } } //Prepare the message for the dialog box to be shown to the user, depending on whether any of the following actions are requried: data migration, uninstallation, or both String userMessage = ""; if (isDataToMigrate && uninstallString != null) { userMessage = "We need to migrate your old data and uninstall the previous version of this app. Would you like to go ahead right now?"; } else if (isDataToMigrate && uninstallString == null) { userMessage = "We need to migrate your old data. Would you like to go ahead right now?"; } else if (!isDataToMigrate && uninstallString != null) { userMessage = "We need to uninstall the previous version of this app. Would you like to go ahead right now?"; } if (isDataToMigrate || uninstallString != null) { MessageBoxResult messageResult = MessageBox.Show(userMessage, "Migration in progress...", MessageBoxButton.YesNo); if (messageResult.Equals(MessageBoxResult.Yes)) { //Migrate user data (if required) if (Directory.Exists(sourceDir)) { //Obtain the path (String) to the "packaged" location, where the previous data will be migrated TO. String destinationDir = Windows.Storage.ApplicationData.Current.LocalFolder.Path; //If you are moving data from one of the redirected folders, you need to use robocopy.exe to bypass redirection. This is the only time you should bypass redirection //Redirected folders: https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-behind-the-scenes //Robocopy.exe: https://technet.microsoft.com/en-us/library/cc733145(v=ws.11 //Otherwise, you should move files using System.IO //Note: The "/move" flag is used to copy data over AND delete previous data in one operation if (RunProcess("robocopy.exe", sourceDir + " " + destinationDir + " /move") > 1) { //Migration was unsuccessful -- App Developer can choose to block/retry/other action } } //Uninstall previous version if (uninstallString != null) { //In this case, the uninstaller takes additional arguments. //Since the uninstallString is app-specific, make sure your call to the uninstaller is properly formatted before calling create process string[] uninstallArgs = uninstallString.Split(' '); if (RunProcess(uninstallArgs[0], uninstallArgs[1]) != 0) { //Uninstallation was unsuccessful - App Developer can choose to block the app here } } } } } else { this.Title = "Desktop App"; this.TitleSpan.Foreground = Brushes.Navy; } var layer = AdornerLayer.GetAdornerLayer(CurrentPhoto); _cropSelector = new RubberbandAdorner(CurrentPhoto) { Window = this }; layer.Add(_cropSelector); #if VISUALCHILD CropSelector.Rubberband.Visibility = Visibility.Hidden; #endif #if NoVISUALCHILD CropSelector.ShowRect = false; #endif Photos = (PhotoList)(this.Resources["Photos"] as ObjectDataProvider)?.Data; Photos.Init(PhotosFolder.Current); ShoppingCart = (PrintList)(this.Resources["ShoppingCart"] as ObjectDataProvider)?.Data; }