开发者

How to display pictures in the project resource?

I have a set of small icons and hope to display them in my application when certain condition occurs, f开发者_如何学编程or example on sunny day, I display the sunny icon.

I can add the jpg files in the picture, and they seem to be uploaded to phone when I deploy the app. However, I don't know how to access these jpgs in my program.

Could someone help? Thanks a lot!


Check this post about content and resources: http://www.windowsphonegeek.com/tips/wp7-working-with-images-content-vs-resource-build-action

To summarize: You should mark your images with a Build Action of Content or Resource, preferably Content. Now you can reference the Content from your Xaml or in code.


If the Build Action for your image resources is set to Content, then you just specify the Source property for the Image control to the relative path to your images:

this._image.Source = new BitmapImage(
    new Uri("/Images/myImage.jpg", UriKind.Relative"));


You can display pictures using the Image element:

<Image Source="/MyImage.png" Visibility="Visible"/>

If you want to switch images according to conditions then you can create multiple images and change each of their Visibility states - or (more preferable) you can create a single image element and change its Source.

Quite how you do this depends on whether you are using databinding or working directly with the UIElements in code behind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜