我希望能够使用我的IsolatedStorage中的图像来修改锁定屏幕背景,但是我无法获得IsolatedStorage文件路径的正确语法来设置锁定屏幕背景。
在以下http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206968(v=vs.105).aspx中,一旦从名为LockHelper
的列表(已从PictureRepository.cs填充)中选择了一个图像,我就会在按钮单击事件中调用Recent
方法它从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路径,但我不确定正确的语法?如果不是这个,还有其他想法吗?
答案 0 :(得分:0)
在nokia developer处尝试此操作。希望你能找到解决方案的方法。
答案 1 :(得分: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来跟踪我的应用存储空间。希望这会有所帮助。