c# - 我的图片没有出现在 listcontrol

标签 c# image windows-phone-7 data-binding mvvm

我不确定这里出了什么问题,但是我的图像没有显示出来。我的对象的所有其他属性都显示出来,但图像永远不会加载。我已经在浏览器中尝试了 url,图像显示在那里。这是我的代码:

使用 MVVM Light,设置 View 模型

DataContext="{Binding Main, Source={StaticResource Locator}}">

我的带有数据绑定(bind)的 xaml
               <ItemsControl ItemsSource="{Binding AllItems}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Height="200">
                                <!--<StackPanel.Background>
                                    <ImageBrush ImageSource="PodImages\podstate-Clip.png" />
                                </StackPanel.Background>-->
                                <Image Source="{Binding ImageUri}"/>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel>
                                        <TextBlock Text="{Binding Summ}" FontSize="32" Foreground="Green"/>
                                        <TextBlock Text="{Binding Brand}" FontSize="32" Foreground="Blue"/>
                                        <TextBlock Text="{Binding L1}" Width="350" TextWrapping="Wrap" Foreground="Blue"/>                                        
                                    </StackPanel>
                                    <TextBlock Text="{Binding Val}"/>

                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

我的数据模型
public class Offer
{

    public long ID { get; set; }
    public int Type { get; set; }
    public string Summ { get; set; }
    public string L1 { get; set; }
    public string Brand { get; set; }
    public string ImageUri { get; set; }
}

我的数据服务回调。这是按预期设置我的收藏。 ImageUri 包含一个有效的 uri。
private void OffersLoaded(OfferDetailsWithMsg offers)
    {
        AllItems = offers.Items.Where(item => item.Type == 0).ToList();
    }

最后是我的 AllItems 属性。是的,我调用 RaisePropertyChanged (为简洁起见删除了支持属性)
public List<Offers> AllItems
    {
        get
        {
            return _allItems;
        }

        set
        {
            if (_allItems == value)
            {
                return;
            }

            _allItems= value;

            RaisePropertyChanged(AllItemsPropertyName);

        }

最佳答案

我相信您需要绑定(bind)到 Uri而不是 string .在 Offer 类中,尝试添加以下属性并绑定(bind)到该属性。

public Uri ImgUri
{
     get
     {   
          return new Uri(ImageUri, UriKind.Absolute); //or relative, if it is relative
     }
}

关于c# - 我的图片没有出现在 listcontrol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10728155/

相关文章:

c# - 如何获取记事本文件保存位置

c# - 如何在Visual Studio Wp8.1中查找应用程序的包名称?

windows-phone-7 - windows phone 7 xaml学习教程

c# - 502 请求 azure 内的支付服务 'website'

c# - 实现 C# Tcp 打洞时出错 - 无法在 NAT 后面连接

image - React Native - 无需缓存即可快速加载图像的更好方法

c# - 比较两个位图图像以检查它们在 WPF 中是否不同的最快方法

mongodb - 如何从命令行查询 Meteor 中的 FS 集合?

c# - 使用MVVM进行搜索

windows-phone-7 - 在 wp7 中找到 IMEI 号?