windows phone 8的锁定屏幕

本文关键字:锁定 屏幕 phone windows | 更新日期: 2023-09-27 18:28:57

嗨,我正在开发一个锁屏应用程序,我正在使用图像列表框。选择图像后,当我点击一个按钮设置锁屏,它应该更新。但它机器人更新。这是我的代码

private async void ApplicationBarIconButton_Click(object sender, EventArgs e)
    {
        MediaLibrary mediaLibrary = new MediaLibrary();
        //ImageSource im = image1.Source;
        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(mediaLibrary.Pictures[imageList.SelectedIndex].GetImage());
        String tempJPEG = "MyWallpaper1.jpg";
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (myIsolatedStorage.FileExists(tempJPEG))
            {
                myIsolatedStorage.DeleteFile(tempJPEG);
            }
            IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
            StreamResourceInfo sri = null;
            Uri uri = new Uri(tempJPEG, UriKind.Relative);
            sri = Application.GetResourceStream(uri);
            WriteableBitmap wb = new WriteableBitmap(bitmap);
            Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 90);
            fileStream.Close();
        }
        LockScreenChange(tempJPEG);
    }
    private async void LockScreenChange(string filePathOfTheImage)
    {
        if (!LockScreenManager.IsProvidedByCurrentApplication)
        {
            await LockScreenManager.RequestAccessAsync();
        }
        if (LockScreenManager.IsProvidedByCurrentApplication)
        {
            var schema = "ms-appdata:///Local/";
            var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);
            LockScreen.SetImageUri(uri);
            var currentImage = LockScreen.GetImageUri();
            MessageBox.Show("Success", "LockScreen changed", MessageBoxButton.OK);
        }
        else
        {
            MessageBox.Show("Background cant be changed. Please check your permissions to this application.");
        }
    }

实际上,当我第一次启动应用程序时,当我点击设置按钮时,当前选择的图像被设置为锁屏,之后当我选择另一个图像时,它显示锁屏已更改,成功。没有错误,也没有例外。我不知道问题出在哪里。请帮忙。。。。。。。。

windows phone 8的锁定屏幕

通过将临时文件名更改为原始文件名(即字符串tempJpeg )来解决此问题