今天被几个Uri搞晕,记录在案,备忘:
1. ApplicationBarIconButton 的Icon Uri: 所引用的Image的Build Action属性必须是"Content"
The URI must point to a file in the application directory. When adding an image file to an project using WindowsPhoneDeveloperTools, you must set theBuild Actionproperty to “Content”. Using the default value “Resource” will not allow the image to be accessed or displayed. - from msdn
且Uri开头须使用反斜杠:
<phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBarIconButton IconUri="/Assets/images/new.png" Text="new list"/> <shell:ApplicationBarIconButton IconUri="/Assets/images/help.png" Text="help" x:Name="btnHelp" Click="btnHelp_Click"/> <shell:ApplicationBarIconButton IconUri="/Assets/images/email.png" Text="feedback"/> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar>
2. WebBrower控件显示本地Html文件内容,使用如下代码:
var s = Application.GetResourceStream(new Uri("Assets/html/Help.txt", UriKind.Relative)); if (s != null) { using (StreamReader reader = new StreamReader(s.Stream)) { wbHelp.NavigateToString(reader.ReadToEnd()); } } else { wbHelp.NavigateToString("Help file not found"); }
其中本地文件help.txt的Build Action属性必须为"Content", 但是!但是!Uri开头不能使用反斜杠
A relative URI that identifies the resource file to be loaded. The URI is relative to the application package and does not need a leading forward slash
from msdn
本文介绍了在Windows Phone应用程序中正确使用Uri的方法。包括ApplicationBarIconButton的IconUri属性设置及WebBrowser控件加载本地HTML文件的注意事项。确保图片资源能够正常显示,并通过不同方式指定资源路径。
1561

被折叠的 条评论
为什么被折叠?



