Beispiel #1
0
        private async void ButtonSetImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
                if (!isProvider)
                {
                    LockScreenRequestResult op = await LockScreenManager.RequestAccessAsync();

                    isProvider = op == LockScreenRequestResult.Granted;
                }
                if (isProvider)
                {
                    if (App.MainViewModel.ImageUri == App.MainViewModel.DefaultImageUri)
                    {
                        LockScreen.SetImageUri(new Uri("ms-appx://" + App.MainViewModel.DefaultImageUriSystem.OriginalString));
                    }
                    else
                    {
                        LockScreen.SetImageUri(new Uri("ms-appdata:///local/" + imageFileNameSystem));
                    }
                    App.MainViewModel.RaisePropertyChanged("IsLockscreen");
                    MessageBox.Show(AppResources.SettingBackgroundSuccess);
                }
                else
                {
                    MessageBox.Show(AppResources.SettingBackgroundError);
                }
            }
            catch { MessageBox.Show(AppResources.SettingBackgroundError); }
        }
Beispiel #2
0
        private async void ApplicationBarIconButton_Click_Wallpaper(object sender, EventArgs e)
        {
            var    viewModel = (PatternDetailViewModel)ViewModel;
            string title     = viewModel.Title;
            string uriString = viewModel.ImageUrl;
            string fileName  = StripInvalidChars(title) + ".jpeg";

            var size         = ResolutionHelper.DisplayResolution;
            int targetWidth  = (int)size.Width;
            int targetHeight = (int)size.Height;

            lock (locker)
            {
                WriteableBitmap writeableBitmap = GetBitmap(uriString, targetWidth, targetHeight);
                SaveImageToIsolatedStorage(writeableBitmap, targetWidth, targetHeight, fileName);
            }

            using (var section = await critSection.EnterAsync())
            {
                if (!LockScreenManager.IsProvidedByCurrentApplication)
                {
                    LockScreenRequestResult result = await LockScreenManager.RequestAccessAsync();

                    if (result == LockScreenRequestResult.Granted)
                    {
                        lock (locker)
                        {
                            SetAsWallpaper(fileName);
                        }
                    }
                }
                else
                {
                    lock (locker)
                    {
                        SetAsWallpaper(fileName);
                    }
                }
            }
        }
Beispiel #3
0
 public static async Task <LockScreenRequestResult> SetLockscreenProvider()
 {
     return(await Task.Run <LockScreenRequestResult>(async() =>
     {
         LockScreenRequestResult result = LockScreenRequestResult.Denied;
         try
         {
             var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
             if (!isProvider)
             {
                 // If you're not the provider, this call will prompt the user for permission.
                 // Calling RequestAccessAsync from a background agent is not allowed.
                 result = await LockScreenManager.RequestAccessAsync();
             }
         }
         catch (System.Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.ToString());
         }
         return result;
     }));
 }