2015-01-07 73 views
0

我遵循此guide。 我能夠通過WCF EXCEPT圖像檢索ListBox中的所有東西。有人能幫助我嗎?無法通過Windows Phone 8中的WCF服務檢索圖像

這是我的課

public Tips() 
{ 
    // 
    // TODO: Add constructor logic here 
    // 
} 

public int TipsId { get; set; } 

public string TipsTitle { get; set; } 

public string TipsDescription { get; set; } 

public string TipsImage { get; set; } 

public string TipsCategory { get; set; } 

public string ImageBind { get; set; } 

Service.cs

 hairtips = new Tips(); 
hairtips.TipsId = myReader.GetInt32(0); 
hairtips.TipsTitle = myReader.GetString(1); 
hairtips.TipsDescription = myReader.GetString(2); 
hairtips.TipsImage = myReader.GetString(3); 
hairtips.TipsCategory = myReader.GetString(4); 

tips.Add(hairtips); 

web服務之後。我的.xaml

<ListBox Height="650" HorizontalAlignment="Left" Margin="11,17,0,0" Name="listBox1" VerticalAlignment="Top" Width="434" > 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Vertical"> 
          <TextBlock Name="LblTitle" HorizontalAlignment="Left" Margin="0,0,0,0" TextWrapping="Wrap" Text="{Binding TipsTitle}" VerticalAlignment="Top"/> 
          <TextBlock Name="LblDesc" HorizontalAlignment="Left" Margin="0,0,0,0" TextWrapping="Wrap" Text="{Binding TipsDescription}" VerticalAlignment="Top" Width="400"/> 

          <Image x:Name="ImageHair" HorizontalAlignment="Stretch" Height="100" Margin="0,0,0,0" VerticalAlignment="Top" Width="100" Source="{Binding TipsImage}" Stretch="Fill"/> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

我的.cs。我在imagebind部分下有錯誤。

public HairTips() 
     { 
      InitializeComponent(); 

      string Category = "Hair"; 

      TipsServiceClient svc = new TipsServiceClient(); 
      svc.getHairTipsCompleted += new EventHandler<getHairTipsCompletedEventArgs>(svc_getHairTipsCompleted); 
      svc.getHairTipsAsync(Category); 
     } 

    void svc_getHairTipsCompleted(object sender, getHairTipsCompletedEventArgs e) 
     { 
List<Tips> listOfTips = new List<Tips>(); 
       foreach (var c in e.Result) 
      { 
      Tips tips = new Tips(); 
      tips.TipsTitle = c.TipsTitle; 
      tips.TipsDescription = c.TipsDescription; 
      tips.TipsImage = c.TipsImage; 
      tips.ImageBind = new BitmapImage(new Uri(tips.TipsImage, UriKind.Absolute)); 
    listOfTips.Add(tips); 
     } 
      listBox1.ItemsSource = listOfTips; 
     } 

請幫助我,如果你知道如何做到這一點。非常感謝你

+0

上調將是有益的任何異常的具體文本。 – lsuarez

+0

「不能將類型'System.Windows.Media.Imaging.BitmapImage'隱式轉換爲'字符串'」這是我在tips.ImageBind = new BitmapImage(new Uri(tips.TipsImage,UriKind.Absolute))下得到的異常。 – Milky

回答

0

嘗試使用Windows.UI.Xaml.Media.Imaging.BitmapImage比使用Windows.Media.Imaging.BitmapImage

並將ImageBind的typeString更改爲BitmapImage

public BitmapImage ImageBind { get; set; } 

參考:Cannot implicitly convert type 'string' to 'Windows.UI.Xaml.Media.Imaging.BitmapImage

+0

它不適合我。我無法把BitmapImage ImageBind {get;設置;} 它給了我一個紅色的線下BitmapImage – Milky

+0

什麼是錯誤?確保你添加了'namespace' http://msdn.microsoft.com/en-US/library/windows/apps/windows.ui.xaml.media.imaging.aspx – Kulasangar

+0

抱歉,超級晚回覆。我已經添加了名稱空間,但它告訴我名稱空間無法找到 – Milky

相關問題