2011-09-19 2 views
0

원격 XML을로드하고 목록 상자에 채우는 응용 프로그램을 만들려고합니다. 나는이 튜토리얼을 따라 갔다. 내가 트위터 피드 URL을 가지고 있으면 휴대 전화에 콘텐츠를 채울 수 있습니다. 하지만 내 XML을 시도하면 화면에 나타나지 않습니다.Windows Phone 7 XML이 목록 상자 오류로 채우기

"System.Diagnostics.Debug.WriteLine (coupon);" 나는 내가 기대하는 XML을 얻고있다. 그래서 위의 코드까지 모든 것이 잘 작동합니다.

당신은 내가 D-> CS -> C -> t 및 D-> CS -> C -> MID 요소를 얻기 위해 노력하고 있어요 내 코드에서 볼 수 있듯이 내 코드

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
     { 
      if (e.Error != null) 
      { 
       System.Diagnostics.Debug.WriteLine("Error: "+e); 
      } 

       DeviceBroker dB = new DeviceBroker(); 
       XElement coupon = XElement.Parse(e.Result); 
       System.Diagnostics.Debug.WriteLine(coupon); 
       MainListBox.ItemsSource = from query in coupon.Descendants("cs") 
              select new ViewModels.LoadCoupon() 
              { 
               CouponName = (string)query.Element("c").Element("t").Value, 
               //MerchantImage = dB.getBaseUri() + "images/merchant/" + (string)query.Element("ms").Element("m").Element("id") 
               MerchantImage = dB.getBaseUri() + "images/merchant/" + (string)query.Element("c").Element("mId") + ".png" 
              }; 

     } 



<d> 
     <ms> 
     <m id="9921" n="The Book Company" /> 
     <m id="6333" n="Earth Rental" /> 
     <m id="6329" n="The Organic Baker" /> 
     <m id="6331" n="News Stand" /> 
     <m id="6327" n="The Jam Company" /> 
     <m id="6325" n="The Fruit Company" /> 
     </ms> 
     <cs> 
     <c id="14533" mId="9921" t="50% Off Any Book Purchase"> 
      <ls> 
      <l id="40145" lng="-0.0724" lat="51.5024" d="4.97" dim="45.91" intX="" intY="" intL="" /> 
      </ls> 
      <cats> 
      <cat id="41" /> 
      <cat id="43" /> 
      </cats> 
      <as /> 
     </c> 
    </cs> 
    </d> 

. NullReferenceException 처리되지 않은 오류가 발생했습니다. 코드에서 .Value를 취하면 화면에서 아무 것도 얻지 못하는 동안 오류가 발생하지 않습니다. 누구든지 그것에 약간의 빛을 분쇄 해 주실 수 있습니까? 더 자세한 정보가 필요하면 알려주십시오.

내 XAML 내 이와같이 보입니다.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
      <ListBox x:Name="MainListBox"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Horizontal" Height="132"> 
          <Image Source="{Binding MerchantImage}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/> 
          <StackPanel Width="370"> 
           <TextBlock Text="{Binding CouponName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
          </StackPanel>        
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
     </Grid> 

답변

1

는 "t"는 요소가 아니라 "C"의 속성 : 당신은 .Attribute ("t") 대신 .Element ("t")

http://msdn.microsoft.com/en-us/library/bb387086.aspx

+0

감사를 사용해야합니다 너 .... 그게 효과가 있었어. .net.에 아주 익숙하지 않았다. 기본 질문을 위해 나를 용서 했어. – Karthik

+0

또한, 단 하나의 레코드가 나타나고있다. 어딘가에 for 루프가없는 것일까? – Karthik