我有一个Windows Phone 7应用程序,我正在尝试将一些常见元素移动到资源文件中。
I have a Windows Phone 7 app and I'm trying to move some common elements into resource files.
文本和样式工作正常但我正在努力找到划分Uri的正确方法。
Text and Styles work fine but I'm struggling to find the right way to partition out Uri's.
这是我试图开始工作的代码示例。
This is a code sample I'm trying to get to work.
<phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBarIconButton IconUri="{StaticResource MenuButton1}" Text="Button1"/> <shell:ApplicationBarIconButton IconUri="{StaticResource MenuButton2}" Text="Button2"/> </shell:ApplicationBar> </phone:PhoneApplicationPage.ApplicationBar>我制作了一个AppImages.xaml文件,这里是代码;
I have made a AppImages.xaml file and here is the code from there;
<ResourceDictionary xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <sys:String x:Key="MenuButton1">/Images/button1.png</sys:String> <sys:String x:Key="MenuButton2">/Images/button2.png</sys:String> </ResourceDictionary>很明显,我不能只使用字符串,但我不知道应该使用什么。
It's clear that I can't just use a string but I don't know what I should use.
我是WP7开发的新手,所以如果我做了明显错误的事情,请告诉我。
I am new to WP7 development so if I'm doing something obviously wrong please let me know.
谢谢, Mike
Thanks, Mike
推荐答案您可以尝试存储 Uri 本身作为资源:
You could try to store the Uri itself as a resource:
<ResourceDictionary xmlns="schemas.microsoft/winfx/2006/xaml/presentation" xmlns:x="schemas.microsoft/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=System"> <sys:Uri x:Key="MenuButton1">/Images/button1.png</sys:Uri> <sys:Uri x:Key="MenuButton2">/Images/button2.png</sys:Uri> </ResourceDictionary>注意 assembly = System in xmlns:sys 名称空间声明。此外,当您在Visual Studio编辑器中键入< sys:时, Uri 将不会显示在IntelliSense中列表,但在XAML中使用它似乎很好。
Note assembly=System in the xmlns:sys namespace declaration. Also, when you type <sys: in the Visual Studio editor, Uri won't be shown in the IntelliSense list, but it seems perfectly fine to use it in XAML.
更多推荐
WP7 Image Uri as StaticResource
发布评论