[UWP Dev] set wallpaper in Windows10 ~userprofilepersonalizationsettings

Source: Internet
Author: User

In the previous wp8.1 and WP8, Microsoft did not publicly set the wallpaper API, only a set of lock screen API, but in WINDOWS10, Microsoft has provided us with the Api:trysetwallpaperimageasync to set the wallpaper, He is defined in the Windows.System.UserProfile.UserProfilePersonalizationSettings class.

Before you use it, you need to call userprofilepersonalizationsettings.issupported () to detect whether the current environment allows custom wallpapers, and if so, to perform subsequent operations.

In the setting of the wallpaper, the location of the wallpaper file is required, you can not arbitrarily specify an address, tested, It is possible to put it in Windows.Storage.ApplicationData.Current.LocalFolder, but previously in 10240, you can also set the image in the project folder as a wallpaper directly from the URI (calling method Windows.Storage.Storag Efile.getfilefromapplicationuriasync ()), but when I tested in 10586, I found it was not working, only in the Localfolder-related position.

if (userprofilepersonalizationsettings.issupported () = True) {    await new Messagedialog ("can set wallpaper Oh ~"). Showasync ();    var current = userprofilepersonalizationsettings.current;    bool Re = await current. Trysetwallpaperimageasync (/*storagefile*/);    if (re = = true)    {        await new Messagedialog ("set Success"). Showasync ();    }    else    {        await new Messagedialog ("Setup failed"). Showasync ();    }} else{    await new Messagedialog ("Do not support setting wallpaper Oh ~"). Showasync ();}

Attach my Demo: Set wallpaper. zip

[UWP Dev] set wallpaper in Windows10 ~userprofilepersonalizationsettings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.