人人人人人人人人人人人人

UWP 设置桌面壁纸、锁屏图片

private static Uri imgUri = new Uri("ms-appx:///pic1.jpg");

    private async void btnSetWallpaper_Click(object sender, RoutedEventArgs e)
    {
        var msg = new MessageDialog("");
        if (!UserProfilePersonalizationSettings.IsSupported())
        {
            //msg = new MessageDialog("人品太差,不支持哦!");
            msg.Content = "人品太差,不支持哦!";
            await msg.ShowAsync();
        }
        //获取文件
        StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(imgUri);

        //设置背景
        UserProfilePersonalizationSettings setting = UserProfilePersonalizationSettings.Current;
        bool b = await setting.TrySetWallpaperImageAsync(file);
        if (b)
        {
            msg.Content = "set ok!";
            await msg.ShowAsync();
        }
        else
        {
            msg.Content = "can not set Wallpaper !";
            await msg.ShowAsync();
        }


    }

设置锁屏图片

private async void btnSetLockScreen_Click(object sender, RoutedEventArgs e)
{
var msg = new MessageDialog("");
if (!UserProfilePersonalizationSettings.IsSupported())
{
//msg = new MessageDialog("人品太差,不支持哦!");
msg.Content = "人品太差,不支持哦!";
await msg.ShowAsync();
}
//获取文件
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(imgUri);

        //设置背景
        UserProfilePersonalizationSettings setting = UserProfilePersonalizationSettings.Current;
        bool b = await setting.TrySetLockScreenImageAsync(file);
        if (b)
        {
            msg.Content = "set ok!";
            await msg.ShowAsync();
        }
        else
        {
            msg.Content = "can not set lock screen!";
            await msg.ShowAsync();
        }


    }
posted @ 2016-03-06 21:06  wgscd  阅读(479)  评论(0编辑  收藏  举报