Windows Phone的图片绑定 [英] Windows Phone Image Binding

查看:110
本文介绍了Windows Phone的图片绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用绑定把图像列表框我

I want to put images in my ListBox using Binding.

下面是包含该对象的URI的

Below is the object containing the URI's:

_roomView.Room = new Room
        {
            Items = new List<Item> {
            new Item {ItemType = ItemType.BlueKey, ImageUri = "/Escape;component/Images/Items/a.jpg"},
            new Item {ItemType = ItemType.Bracelet, ImageUri = "/Escape;component/Images/Items/b.png"},
            new Item {ItemType = ItemType.Money, ImageUri = "/Escape;component/Images/Items/b.png"}}
        };
        DataContext = _roomView;

下面是XML:

  <ListBox x:Name="Mylist">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="5">
                        <Image Source="{Binding Room.Items.ImageUri}" Stretch="None" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

图像无法显示。

The images aren't showing.

任何人都可以看到我错了?

Can anyone see where I am going wrong?

推荐答案

如果图像不显示
- 检查pathes;
例如我的code结合

If image doesn't show - check pathes; For example my code for binding

 public class Country
{       
    public String name
    {
        get;
        set;
    }       
    public String Flag
    {
        get
        {
            return "/Image/Countries/" + name + ".png";
        }
    }
}


<Image Width="100" Height="140" HorizontalAlignment="Left" Stretch="UniformToFill">
    <Image.Source>
       <BitmapImage UriSource="{Binding Flag}" CreateOptions="BackgroundCreation" />
    </Image.Source>
</Image>   

如果您使用的是从项目的图像确保大公构建内容,并始终复制到输出目录。(图像属性)

If You are using images from the project be sure that thay Build to content and copy always to output directory.(properties of the images )

通过,如果你想显示从互联网上你需要使用图像的方式LowProfileImageLoader
你可以阅读更多关于它
<一href=\"http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx

By the way if you want to show images from the Internet You need to use LowProfileImageLoader You can read more about it http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx

 <Image  delay:LowProfileImageLoader.UriSource= "{Binding Flag}" HorizontalAlignment="Left" Stretch="Fill"   VerticalAlignment="Center" Width="24" Height="16" Margin="0,0,10,0"  />

这篇关于Windows Phone的图片绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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