UAP Development Error The given System.Uri cannot be converted into a Windows.Foundation.Uri (Windows phone background replacement)

Source: Internet
Author: User

Today, bloggers in the development of a Windows Phone app, want to implement the app background replacement, the idea is simple. Use the Applicationdatacontainer container to store my picture path, read the path each time I load the app to determine what background I use, and then change the value of the container when changing the background. The relevant code is as follows:

Applicationdatacontainer localsetting =ApplicationData.Current.LocalSettings;

Localsetting. values["Background"] = "ms-appx:///assets/images/background2.jpg";Button btn= Sender asButton; if(string. Equals (btn. Tag,"1") {localsetting. values["Background"] ="ms-appx:///assets/images/background1.jpg"; } Else if(string. Equals (btn. Tag,"2") {localsetting. values["Background"] ="ms-appx:///assets/images/background2.jpg"; } Else{localsetting. values["Background"] ="ms-appx:///assets/images/background3.jpg"; }

When loading the application, brush the background of the grid with the image corresponding to the container path, where the Contentpanel is a grid:

         if(!localsetting. values["Background"]. Equals (NULL))            {                stringStrimageuri = localsetting. values["Background"].                ToString (); if(!string. IsNullOrEmpty (Strimageuri)) {ImageBrush ImageBrush=NewImageBrush (); Imagebrush.imagesource=NewBitmapImage (NewUri (Strimageuri, Urikind.relativeorabsolute)); Contentpanel.background=ImageBrush; }            }

It is important to note that my pictures are placed in the image folder below the assets folder in the project, and the values in my container initially are similar to this:

Localsetting. values["Background" "assets/images/background2.jpg";

Then you will get an error: The given System.Uri cannot is converted into a Windows.Foundation.Uri, now the URI definition seems to have been modified, specific reference: https:// Msdn.microsoft.com/zh-cn/library/windows/apps/windows.foundation.uri (v=vs.85). aspx

My solution is to add a ms-appx:///in front of the path, note that this is an absolute path, UriKind should be set to Urikind.relativeorabsolute or Urikind.absolute

UAP Development Error The given System.Uri cannot be converted into a Windows.Foundation.Uri (Windows phone background replacement)

Related Article

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.