WP7 图像 Uri 作为静态资源 [英] WP7 Image Uri as StaticResource
问题描述
我有一个 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/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.
谢谢,迈克
推荐答案
您可以尝试将 Uri
本身存储为资源:
You could try to store the Uri
itself as a resource:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/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>
注意 xmlns:sys
命名空间声明中的 assembly=System
.此外,当您在 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 图像 Uri 作为静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!