Home > Article > Backend Development > Example tutorial on using Uri under WPF
Background
I want to use a map in a WPF development project. The original Google map was blocked, and now I use Baidu map instead. Baidu Map's JavaScript API is used to call the Baidu Map application. On the WPF platform, Webbroswer is used for access. In the process, Webbroswer.Navigate is used to load the html file. The resource used by Navigate is Uri, which accesses the currently running file by default. The resources under the folder are also the resources under /bin/Debug.
We can solve this problem by placing our html file directly under the Debug file. How to access the current running folder? Refer to Appendix 1. The problem can be solved at this point, but when our project applies Git version control, Git will not put the contents of the /bin/Debug file into version control by default. That is to say, if others clone through version control As for our project, there is a lack of html files in the project. The problem we have to face now is how to use Uri to load resources under relative paths.
Solution
Solution 1:
Still access the resources under the current folder, by setting the properties of the resources, copy the resources to the project's /bin/Debug during compilation. The specific method is to add your resources to the project, and then change its properties from "Copy to output directory" to "Always copy" to generate the operation "content". For specific methods, please refer to
http://blog.csdn .net/yulongguiziyao/article/details/25131597
Solution 2:
Access through relative paths, put your resources in the project folder, and then access the upper level by getting "../../" directory to obtain. For example, add the ThirdParty folder to the project, and add the resource BMap.html I want under ThirdParty in the project. I can access the resource with the following statement:
new Uri(System.Environment.CurrentDirectory + @"/../../ThirdParty/BMap.html", UriKind.RelativeOrAbsolute)
System.Environemnt.CurrentDirectory That is, the /bin/Debug directory, and you return to the project directory through /../../. In this way, there is a ThirdParty directory under the project directory, and we can directly access this resource. At the same time, this resource can also be released through version control. Once you get out, the problem will be solved.
The above is the detailed content of Example tutorial on using Uri under WPF. For more information, please follow other related articles on the PHP Chinese website!