【发布时间】:2013-08-20 04:24:32
【问题描述】:
我希望能够使用我的 IsolatedStorage 中的图像来修改锁定屏幕背景,但我无法获取 IsolatedStorage 文件路径的正确语法来设置锁定屏幕背景。
在http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206968(v=vs.105).aspx 之后,一旦从名为Recent 的列表中选择了图像,我将在按钮单击事件中调用LockHelper 方法(该列表已从PictureRepository.cs 填充,从IsolatedStorage 加载图像)
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。我引用的所有地方都说使用IsolatedStorage Uri 应该是ms-appdata:///local/ 然后是IsolatedStorage 文件路径(在我的情况下为Pictures/imagename.jpg),我相信我的错误在于Uri 路径,但我不确定的正确语法?如果不是这个,还有其他想法吗?
【问题讨论】:
-
您是否尝试跳过架构前缀之一(“isostore”或“ms-app...”)?也许不能同时应用它们。
-
你一定是在我更新编辑之前发现了我。我确实删除了 isostore 前缀并以 ArgumentException 告终。我会尝试删除 ms-app 看看会发生什么..
-
我相信它确实与架构前缀有关,尽管我不确定修复是什么?这被证明很有趣social.msdn.microsoft.com/Forums/wpapps/en-US/…。我确信我的图像存在于 IsolatedStorage 中,因为它正在加载到我的视图中。
标签: c# windows-phone-8 isolatedstorage lockscreen