【问题标题】:My images aren't showing up in listcontrol我的图片没有出现在 listcontrol
【发布时间】:2012-05-30 11:39:58
【问题描述】:

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

使用 MVVM Light,设置视图模型

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

我的带有数据绑定的 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);

        }

【问题讨论】:

  • 你检查过页面的来源吗?
  • 这是一个 Windows 手机应用程序,除非有人知道如何做到这一点,否则我无法查看结果源
  • 我在网上硬编码了一个随机图片的网址,结果成功了。不知道为什么它不会显示我的 cdn 中的图像。
  • 您是否检查过从 CDN 返回的标头?也许它没有设置 MIME 类型,或者类似的,Image 控件无法确定它是图像?
  • 谢谢,好主意。我会检查一下。

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    啊,这些是 Gif,似乎不支持 Gif。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-06
      • 1970-01-01
      • 1970-01-01
      • 2022-07-21
      • 2018-05-30
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多