0

我希望能够使用来自我的 IsolatedStorage 的图像来修改锁定屏幕背景,但我无法获得正确的 IsolatedStorage 文件路径语法来设置锁定屏幕背景。

在以下http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206968(v=vs.105).aspxLockHelper中,一旦从中选择了图像,我将在按钮单击事件中调用该方法一个名为的列表Recent(已从 PictureRepository.cs 填充,它从独立存储中加载图像)

private void recent_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {            
        capturedPicture = (sender as LongListSelector).SelectedItem as CapturedPicture;

        if (capturedPicture != null)
        {
            //filename is the name of the image in IsolatedStorage
            fileName = capturedPicture.FileName;
        }
    }

void setAsLockScreenMenuItem_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(fileName)) 
        {
            //PictureRepository.IsolatedStoragePath is a string = "Pictures"                
            LockHelper("isostore:/" + PictureRepository.IsolatedStoragePath + "/" + fileName, false);  //results in FileNotFoundException
            LockHelper(PictureRepository.IsolatedStoragePath + "/" + fileName, false);  //results in ArgumentException
        }
        else
        {
            MessageBoxResult result = MessageBox.Show("You must select an image to set it as your lock screen.", "Notice", MessageBoxButton.OK);
            if (result == MessageBoxResult.OK)
            {
                return;
            }
        }
    }

一旦LockHelper被调用,事件就会继续

private async void LockHelper(string filePathOfTheImage, bool isAppResource)
    {
        try
        {
            var isProvider = Windows.Phone.System.UserProfile.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.
                var op = await Windows.Phone.System.UserProfile.LockScreenManager.RequestAccessAsync();

                // Only do further work if the access was granted.
                isProvider = op == Windows.Phone.System.UserProfile.LockScreenRequestResult.Granted;
            }

            if (isProvider)
            {
                // At this stage, the app is the active lock screen background provider.

                // The following code example shows the new URI schema.
                // ms-appdata points to the root of the local app data folder.
                // ms-appx points to the Local app install folder, to reference resources bundled in the XAP package.
                var schema = isAppResource ? "ms-appx:///" : "ms-appdata:///Local/";
                var uri = new Uri(schema + filePathOfTheImage, UriKind.Absolute);

                //The Error Occurs Here!
                // Set the lock screen background image.
                Windows.Phone.System.UserProfile.LockScreen.SetImageUri(uri);

                // Get the URI of the lock screen background image.
                var currentImage = Windows.Phone.System.UserProfile.LockScreen.GetImageUri();
                System.Diagnostics.Debug.WriteLine("The new lock screen background image is set to {0}", currentImage.ToString());
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("Cannot update your lock screen background at this time.", "Notice", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }
        }
        catch (System.Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
    }

错误发生在Windows.Phone.System.UserProfile.LockScreen.SetImageUri(uri);方法内LockHelper。它要么是FileNotFoundException提及The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B),要么是 ArgumentException。我引用的所有地方都说Uri应该使用IsolatedStorage ms-appdata:///local/,然后使用IsolatedStorage 文件路径(在我的情况下为Pictures/imagename.jpg),我相信我的错误在于Uri 路径,但我不确定正确的语法?如果不是这个,还有其他想法吗?

4

2 回答 2

0

Try this at nokia developer. Hope you'll get the way to the solution.

于 2013-08-20T05:00:58.157 回答
0

这对我有用:

const string filePathOfTheImage = "/Shared/ShellContent/shot2.jpg"; //This is where my image is in isostore

var uri = new Uri("ms-appdata:///local" + filePathOfTheImage, UriKind.Absolute);

此外,我使用WP Power Tools来跟踪我的应用程序存储空间。希望这可以帮助。

于 2014-02-21T12:18:28.973 回答