WP7 Image Uri as StaticResource [英] WP7 Image Uri as StaticResource

查看:110
本文介绍了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.

谢谢,
Mike

Thanks, Mike

推荐答案

您可以尝试存储 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>

注意 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆