1,打开WMAppManifest.xml.添加
<Extensions>
<Extension ExtensionName="LockScreen_Wallpaper" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
</Extensions>
2,添加事件
private async void buttonSet_Click(object sender, RoutedEventArgs e)
{
Uri nextImageUri;
nextImageUri = new Uri("file:///" + Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "/DefaultWallpaper.jpg", UriKind.RelativeOrAbsolute);
try
{
bool isProvider = Windows.Phone.System.UserProfile.LockScreenWallpaperManager.IsProvidedByCurrentApplication;
if (isProvider)
{
Windows.Phone.System.UserProfile.LockScreenWallpaper.SetImageUri(nextImageUri);
}
else
{
var op = await LockScreenWallpaperManager.RequestAccessAsync();
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
{
Uri nextImageUri;
nextImageUri = new Uri("file:///" + Windows.ApplicationModel.Package.Current.InstalledLocation.Path + "/DefaultWallpaper.jpg", UriKind.RelativeOrAbsolute);
try
{
bool isProvider = Windows.Phone.System.UserProfile.LockScreenWallpaperManager.IsProvidedByCurrentApplication;
if (isProvider)
{
Windows.Phone.System.UserProfile.LockScreenWallpaper.SetImageUri(nextImageUri);
}
else
{
var op = await LockScreenWallpaperManager.RequestAccessAsync();
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
From SDK:
Lock screen background for Windows Phone

【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步