如何从窗口手机8中的xml文件绑定数据?

时间:2014-08-24 02:29:36

标签: c# xml windows-phone-7 windows-phone-8 visual-studio-2013

我想得到所有" DryItemName"属于我的" ProductDry.xml"文件基于" DryCategoryId"。当我在下面执行我的查询时,我只能得到第一个" DryItemName"属于" DryCategoryId"属性。

如何获得所有" ItemDryName"属性?

<?xml version="1.0" encoding="utf-8" ?>

<ProductsDry> 
  <!-- Cleansers -->
  <DryCategory DryCategoryId="1" DryCategoryName="Cleansers">
    <ItemDry ItemDryId="1" ItemDryName="Alpha Hydrox Foaming Face Wash"
             ItemDryLink="http://www.somalystore.com/?product=alpha-hydrox-3"
             ItemDryImage="images/BP305.jpg" />
    <ItemDry ItemDryId="2" ItemDryName="CeraVe Facial Cleanser"
             ItemDryLink="http://www.somalystore.com/?product=cerave-cerave-foaming-facial-cleanser"
             ItemDryImage="images/CV001.jpg" />
    <ItemDry ItemDryId="3" ItemDryName="DHC Cleansing Milk"
             ItemDryLink="http://www.somalystore.com/?product=dhc-2"
             ItemDryImage="images/BP310.jpg" />
    <ItemDry ItemDryId="4" ItemDryName="Neutrogena Extra Gentle Cleanser"
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-extra-gentle-cleanser"
             ItemDryImage="images/NT001.jpg" />
    <ItemDry ItemDryId="5" ItemDryName="Olay Sensitive 4-In-1 Daily Facial Cloths"
             ItemDryLink="http://www.somalystore.com/?product=olay-sensitive-4-in-1-daily-facial-cloths-33-count"
             ItemDryImage="images/OL001.jpg" />
    <ItemDry ItemDryId="6" ItemDryName="The Body Shop Aloe Gentle Facial Wash "
             ItemDryLink="http://www.somalystore.com/?product=the-body-shop"
             ItemDryImage="images/BP307.jpg" />
    <ItemDry ItemDryId="7" ItemDryName="Yes to Cucumbers Gentle Milk Cleanser"
             ItemDryLink="http://www.somalystore.com/?product=yes-to-cucumbers-gentle-milk-cleanserp"
             ItemDryImage="images/YE001.jpg" />
    <ItemDry ItemDryId="8" ItemDryName="Elemis Soothing Chamomile Cleanser "
             ItemDryLink="http://www.somalystore.com/?product=elemis"
             ItemDryImage="images/BP308.jpg" />
    <ItemDry ItemDryId="9" ItemDryName="POND’S Cold Cream Cleanser"
             ItemDryLink="http://www.somalystore.com/?product=ponds"
             ItemDryImage="images/BP309.jpg" />
    <ItemDry ItemDryId="10" ItemDryName="DHC Deep Cleansing Oil"
             ItemDryLink="http://www.somalystore.com/?product=dhc"
             ItemDryImage="images/BP306.jpg" />
    <ItemDry ItemDryId="11" ItemDryName="CeraVe Hydrating Cleanser"
             ItemDryLink="http://www.somalystore.com/?product=cerave-hydrating-cleanser"
             ItemDryImage="images/CV003.jpg" />
    <ItemDry ItemDryId="12" ItemDryName="Burt's Bees Soap Bark and Chamomile Deep Cleansing Cream "
             ItemDryLink="http://www.somalystore.com/?product=burts-bees-2"
             ItemDryImage="images/BP311.jpg" />
    <ItemDry ItemDryId="13" ItemDryName="Olay Total Effects Nourishing Cream Cleanser "
             ItemDryLink="http://www.somalystore.com/?product=olay-4"
             ItemDryImage="images/BP312.jpg" />
  </DryCategory>

  <!-- Day Cream -->
  <DryCategory DryCategoryId="2" DryCategoryName="Day Cream">
    <ItemDry ItemDryId="14" ItemDryName="Neutrogena Ageless Intensives Tone Correcting Moisture SPF30 "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-ageless-intensives-tone-correcting-moisture-spf-30"
             ItemDryImage="images/dayCream1.jpg" />
    <ItemDry ItemDryId="15" ItemDryName="Yes To Carrots Fragrance Free Daily Moisturizer SPF 15"
             ItemDryLink="http://www.somalystore.com/?product=yes-to-carrots-daily-facial-moisturizer-with-spf-15"
             ItemDryImage="images/YE003.JPG" />
    <ItemDry ItemDryId="16" ItemDryName="Aveeno Positively Radiant Skin Daily Moisturizer SPF15 "
             ItemDryLink="http://www.somalystore.com/?product=aveeno-positively-radiant-skin-daily-moisturizer-spf-15"
             ItemDryImage="images/AV014.JPG" />
    <ItemDry ItemDryId="17" ItemDryName="Aveeno Active Naturals Ultra Calming Daily Moisturizer SPF15 "
             ItemDryLink="http://www.somalystore.com/?product=aveeno-daily-moisturizer-ultra-calming-spf-15"
             ItemDryImage="images/AV019.jpg" />
    <ItemDry ItemDryId="18" ItemDryName="Neutrogena Healthy Skin Face Lotion SPF 15 "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-healthy-skin-radiance-cream-spf-15"
             ItemDryImage="images/NT048.JPG" />
    <ItemDry ItemDryId="19" ItemDryName="Olay Complete Daily Defense All Day Moisturizer With Sunscreen SPF30 "
             ItemDryLink="http://www.somalystore.com/?product=olay-5"
             ItemDryImage="images/BP314.png" />
    <ItemDry ItemDryId="20" ItemDryName="Blue Lizard Australian Sunscreen Sensitive SPF 30 "
             ItemDryLink="http://www.somalystore.com/?product=blue-lizard"
             ItemDryImage="images/BP254.jpg" />
    <ItemDry ItemDryId="21" ItemDryName="Eucerin Q10 Anti-Wrinkle Sensitive Skin Lotion Broad Spectrum SPF15 "
             ItemDryLink="http://www.somalystore.com/?product=eucerin-sensitive-facial-skin-q10-anti-wrinkle-sensitive-skin-lotion-with-spf-15-sunscreen"
             ItemDryImage="images/EU006.JPG" />
    <ItemDry ItemDryId="22" ItemDryName="Nia24 Prevention 100% Mineral Sunscreen SPF 30 "
             ItemDryLink="http://www.somalystore.com/?product=nia24-3"
             ItemDryImage="images/BP315.jpg" />
    <ItemDry ItemDryId="23" ItemDryName="Neutrogena Visibly Even Daily Moisturizer, SPF 30 "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-visibly-even-daily-moisturizer-spf-30-2"
             ItemDryImage="images/NT038.JPG" />
    <ItemDry ItemDryId="24" ItemDryName="Aveeno Active Naturals Positively Ageless Youth Perfecting Moisturizer, SPF 30 "
             ItemDryLink="http://www.somalystore.com/?product=aveeno-active-naturals-positively-ageless-youth-perfecting-day-moisturizer-spf-30"
             ItemDryImage="images/AV013.JPG" />
    <ItemDry ItemDryId="25" ItemDryName="Cetaphil Fragrance Free Daily Facial Moisturizer, SPF 15 "
             ItemDryLink="http://www.somalystore.com/?product=cetaphil-fragrance-free-daily-facial-moisturizer-spf-15"
             ItemDryImage="images/CP006.JPG" />
  </DryCategory>

  <!-- Night Cream -->
  <DryCategory DryCategoryId="3" DryCategoryName="Night Cream">
    <ItemDry ItemDryId="26" ItemDryName="Neutrogena Ageless Restoratives Anti-Oxidant Booster Serum "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-4"
             ItemDryImage="images/BP316.png" />
    <ItemDry ItemDryId="27" ItemDryName="Josie Maran Argan Oil"
             ItemDryLink="http://www.somalystore.com/?product=josie-maran"
             ItemDryImage="images/BP317.jpg" />
    <ItemDry ItemDryId="28" ItemDryName="Neutrogena Healthy Skin AntiWrinkle Cream Original Formula "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-healthy-skin-anti-wrinkle-cream-night-formula"
             ItemDryImage="images/NT030.JPG" />
    <ItemDry ItemDryId="29" ItemDryName="Aveeno Ageless Vitality Restorative Night Treatmen"
             ItemDryLink="http://www.somalystore.com/?product=aveeno-ageless-vitality-restorative-night-treatment"
             ItemDryImage="images/AV022.jpg" />
    <ItemDry ItemDryId="30" ItemDryName="Eucerin Redness Relief Soothing Night Crème "
             ItemDryLink="http://www.somalystore.com/?product=eucerin-redness-relief-soothing-night-creme"
             ItemDryImage="images/EU003.jpg" />
    <ItemDry ItemDryId="31" ItemDryName="Atopalm Intensive Moisturizing Cream "
             ItemDryLink="http://www.somalystore.com/?product=atopalm"
             ItemDryImage="images/BP318.jpg" />
    <ItemDry ItemDryId="32" ItemDryName="CeraVe Moisturizing Facial Lotion PM Night "
             ItemDryLink="http://www.somalystore.com/?product=cerave-facial-moisturizing-lotion-pm"
             ItemDryImage="images/CV004.JPG" />
    <ItemDry ItemDryId="33" ItemDryName="RoC Multi-Correxion Night Treatment"
             ItemDryLink="http://www.somalystore.com/?product=roc-multi-correxion-night-treatment"
             ItemDryImage="images/EU006.JPGRO003.png" />
    <ItemDry ItemDryId="34" ItemDryName="Olay Skin Tightening Serum"
             ItemDryLink="http://www.somalystore.com/?product=olay-6"
             ItemDryImage="images/BP319.1.jpg" />
    <ItemDry ItemDryId="35" ItemDryName="Eucerin Q10 Anti-Wrinkle Sensitive Skin cream "
             ItemDryLink="http://www.somalystore.com/?product=eucerin-q10-anti-wrinkle-sensitive-skin-creme"
             ItemDryImage="images/EU005.JPG" />
    <ItemDry ItemDryId="36" ItemDryName="Vivite Night Renewal Facial Cream"
             ItemDryLink="http://www.somalystore.com/?product=vivite-2"
             ItemDryImage="images/BP320.jpg" />
    <ItemDry ItemDryId="37" ItemDryName="Neutrogena Ageless Intensives Deep Wrinkle Moisture "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-ageless-intensives-deep-wrinkle-moisture-night"
             ItemDryImage="images/NT040.JPG" />
    <ItemDry ItemDryId="39" ItemDryName="Roc Retinol Correxion Deep-Wrinkle Night Cream "
             ItemDryLink="http://www.somalystore.com/?product=roc-retinol-correxion-deep-wrinkle-night-cream"
             ItemDryImage="images/RO009.jpg" />
  </DryCategory>

  <!-- Exfoliators et Peel -->
  <DryCategory DryCategoryId="4" DryCategoryName="Exfoliators et Peel">
    <ItemDry ItemDryId="40" ItemDryName="Vivite Vivite Exfoliating Facial Cleanser"
             ItemDryLink="http://www.somalystore.com/?product=vivite"
             ItemDryImage="images/BP278.jpg" />
    <ItemDry ItemDryId="41" ItemDryName="Clinique Scrub Cream Rinse-Off Formula "
             ItemDryLink="http://www.somalystore.com/?product=clinique-2"
             ItemDryImage="images/BP272.jpg" />
    <ItemDry ItemDryId="42" ItemDryName="CLARISONIC Mia 2 Sonic Cleansing System(pink)"
             ItemDryLink="http://www.somalystore.com/?product=clarisonic-mia-2-sonic-cleansing-system"
             ItemDryImage="images/BP280pink.jpg" />
    <ItemDry ItemDryId="43" ItemDryName="100 Percent Pure Red Wine Resveratrol Scrub and Mask"
             ItemDryLink="http://www.somalystore.com/?product=100-percent-pure"
             ItemDryImage="images/BP313.jpg" />
  </DryCategory>

  <!-- Masks -->
  <DryCategory DryCategoryId="5" DryCategoryName="Masks">
    <ItemDry ItemDryId="44" ItemDryName="DDF sulfur therapeutic facial mask "
             ItemDryLink="http://www.somalystore.com/?product=astara-copy"
             ItemDryImage="images/BP265.jpg" />
    <ItemDry ItemDryId="45" ItemDryName="Peter Thomas Roth Sulfur Cooling Facial Masque"
             ItemDryLink="http://www.somalystore.com/?product=peter-thomas-roth"
             ItemDryImage="images/BP263.png" />
    <ItemDry ItemDryId="46" ItemDryName="MD Formulations Moisture Defense Antioxidant Treatment Masque"
             ItemDryLink="http://www.somalystore.com/?product=md-formulations"
             ItemDryImage="images/BP321.jpg" />
    <ItemDry ItemDryId="47" ItemDryName="Elizabeth Arden Hydrating Mask"
             ItemDryLink="http://www.somalystore.com/?product=elizabeth-arden-5"
             ItemDryImage="images/BP322.jpg" />
    <ItemDry ItemDryId="48" ItemDryName="Fresh Rose Face Mask "
             ItemDryLink="http://www.somalystore.com/?product=fresh"
             ItemDryImage="images/BP323.1.jpg" />
    <ItemDry ItemDryId="49" ItemDryName="Freeman Cucumber Facial Peel-Off Mask "
             ItemDryLink="http://www.somalystore.com/?product=freeman-feeling-beautiful-facial-peel-off-mask-cucumber-skin-silkening"
             ItemDryImage="images/FM003.jpg" />
  </DryCategory>

  <!-- Foundation -->
  <DryCategory DryCategoryId="6" DryCategoryName="Foundation">
    <ItemDry ItemDryId="50" ItemDryName="Neutrogena Healthy Skin Liquid Makeup "
             ItemDryLink="http://www.somalystore.com/?product=neutrogena-healthy-skin-liquid-makeup-spf-20"
             ItemDryImage="images/BP080_Natural_Beige.jpg" />
    <ItemDry ItemDryId="51" ItemDryName="Jane Iredale PurePressed Base Mineral Foundation SPF 20"
             ItemDryLink="http://www.somalystore.com/?product=jane-iredale-2"
             ItemDryImage="images/BP324_Teakwood.jpg" />
    <ItemDry ItemDryId="52" ItemDryName="Jane Iredale Dream Tint Tinted Moisturizer Spf 15"
             ItemDryLink="http://www.somalystore.com/?product=jane-iredale-3"
             ItemDryImage="images/BP325_Peach_Brightener.jpg" />
    <ItemDry ItemDryId="53" ItemDryName="CoverGirl Smoothers SPF 15 BB Cream Tinted Moisture"
             ItemDryLink="http://www.somalystore.com/?product=covergirl-2"
             ItemDryImage="images/BP326_Medium_ToDark815.jpg" />
    <ItemDry ItemDryId="54" ItemDryName="No7 True Identity Foundation"
             ItemDryLink="http://www.somalystore.com/?product=boots-no7-true-identity-foundation"
             ItemDryImage="images/BO047.JPG" />
    <ItemDry ItemDryId="55" ItemDryName="Maybelline New York Dream Liquid Mousse Foundation"
             ItemDryLink="http://www.somalystore.com/?product=maybelline-dream-liquid-mousse-airbrush-finish"
             ItemDryImage="images/ML001_ClassicIvory.jpg" />
  </DryCategory>

  <!-- Power -->
    <DryCategory DryCategoryId="7" DryCategoryName="Power">
      <ItemDry ItemDryId="56" ItemDryName="Mary Kay Mineral Powder Foundation"
               ItemDryLink="http://www.somalystore.com/?product=mary-kay"
               ItemDryImage="images/BP327Ivory2.jpg" />
      <ItemDry ItemDryId="57" ItemDryName="Urban Decay Razor Sharp Ultra Definition Finishing Powder"
               ItemDryLink="http://www.somalystore.com/?product=urban-decay"
               ItemDryImage="images/BP328.jpg" />
      <ItemDry ItemDryId="58" ItemDryName="L'Oreal Paris True Match Naturale Soft-Focus Mineral Finish"
               ItemDryLink="http://www.somalystore.com/?product=loreal-paris-true-match-naturale-mineral-foundation-spf-19"
               ItemDryImage="images/BP073SunBeige.jpg" />
      <ItemDry ItemDryId="59" ItemDryName="Almay Line Smoothing Pressed Powder"
               ItemDryLink="http://www.somalystore.com/?product=almay-line-smoothing-pressed-powder-face-powders"
               ItemDryImage="images/AL010Medium300.JPG" />
      <ItemDry ItemDryId="60" ItemDryName="CoverGirl Trublend Minerals Pressed Powder"
               ItemDryLink="http://www.somalystore.com/?product=covergirl-trublend-pressed-powder"
               ItemDryImage="images/BP091TranslucentMedium4.JPG" />
      <ItemDry ItemDryId="61" ItemDryName="CoverGirl Advanced Radiance Age-Defying Pressed Powder"
               ItemDryLink="http://www.somalystore.com/?product=covergirl-advanced-radiance-age-defying-pressed-powder"
               ItemDryImage="images/CG011ClassicBeige115.JPG" />
      <ItemDry ItemDryId="62" ItemDryName="Maybelline New York Fit Me! Powder"
               ItemDryLink="http://www.somalystore.com/?product=maybelline-fit-me-pressed-powder"
               ItemDryImage="images/ML009.jpg" />
      <ItemDry ItemDryId="63" ItemDryName="Neutrogena Healthy Skin Pressed Powder, SPF 20"
               ItemDryLink="http://www.somalystore.com/?product=neutrogena-healthy-skin-pressed-powder-compact-spf-20"
               ItemDryImage="images/BP094Light20.JPG" />
      <ItemDry ItemDryId="64" ItemDryName="Maybelline New York Instant Age Rewind The Perfector Powder "
               ItemDryLink="http://www.somalystore.com/?product=maybelline-instant-age-rewind-the-perfector-powder"
               ItemDryImage="images/BP116Medium.JPG" />
  </DryCategory>

  <!-- Facial waters -->
    <DryCategory DryCategoryId="8" DryCategoryName="Facial waters">
      <ItemDry ItemDryId="65" ItemDryName="Twinlab Na-PCA Natural Moisturizing Factor in Human Skin with Aloe Vera"
               ItemDryLink="http://www.somalystore.com/?product=twinlab"
               ItemDryImage="images/BP330.jpg" />
      <ItemDry ItemDryId="66" ItemDryName="Avene Thermal Spring Water"
               ItemDryLink="http://www.aveneusa.com/thermal-spring-water-1"
               ItemDryImage="images/AveneThermalSpringWater.jpg" />
      <ItemDry ItemDryId="67" ItemDryName="La Roche-Posay Thermal Spring Water"
               ItemDryLink="http://www.laroche-posay.com/products-treatments/Thermal-spring-water/Thermal-Spring-Water-by-La-Roche-Posay-p6268.aspx"
               ItemDryImage="images/LaRoche-PosayThermalSpringWater.png" />
      <ItemDry ItemDryId="68" ItemDryName="Vichy Eau Thermale Spray"
               ItemDryLink="http://www.vichyusa.com/search?cgid=thermal-spa-water"
               ItemDryImage="images/VichyEauThermaleSpray.jpg" />
      <ItemDry ItemDryId="69" ItemDryName="evian mineral water spray"
               ItemDryLink="http://www.evian.com/en_int/56-evian-Facial-Spray"
               ItemDryImage="images/evian-mineral-wate-spray.jpg" />
  </DryCategory>

  <!-- Eye Cream -->
  <DryCategory DryCategoryId="9" DryCategoryName="Eye Cream">
      <ItemDry ItemDryId="70" ItemDryName="Neutrogena Rapid Wrinkle Repair Eye Cream"
               ItemDryLink="http://www.somalystore.com/?product=neutrogena-healthy-skin-eye-cream"
               ItemDryImage="images/NT046.jpg" />
      <ItemDry ItemDryId="71" ItemDryName="Aveeno Ageless Vitality Revitalizing Eye Treatment "
               ItemDryLink="http://www.somalystore.com/?product=aveeno-ageless-vitality-revitalizing-eye-treatment"
               ItemDryImage="images/AV021.jpg" />
      <ItemDry ItemDryId="72" ItemDryName="Olay Regenerist Eye Lifting Serum 0.5 fl oz (15 ml)"
               ItemDryLink="http://www.somalystore.com/?product=olay-regenerist-eye-lifting-serum"
               ItemDryImage="images/OL024.jpg" />
      <ItemDry ItemDryId="73" ItemDryName="Roc Retinol Correxion Sensitive Cream"
               ItemDryLink="http://www.somalystore.com/?product=roc-retinol-correxion-sensitive-cream-2"
               ItemDryImage="images/RO014.jpg" />
      <ItemDry ItemDryId="74" ItemDryName="Origins Eye Doctor Moisture Care"
               ItemDryLink="http://www.somalystore.com/?product=origins-eye-doctor-moisture-care-for-skin-around-eyes"
               ItemDryImage="images/BP331.jpg" />
      <ItemDry ItemDryId="75" ItemDryName="Relastin Eye Silk"
               ItemDryLink="http://www.somalystore.com/?product=relastin"
               ItemDryImage="images/BP332.jpg" />
  </DryCategory>

  <!-- Lip care -->
  <DryCategory DryCategoryId="10" DryCategoryName="Lip care">
      <ItemDry ItemDryId="76" ItemDryName="eos Smooth Lip Balm Sphere, Lemon Drop"
               ItemDryLink="http://www.somalystore.com/?product=eos-smooth-lip-balm-sphere-lemon-drop"
               ItemDryImage="images/BP248-Lemon-Drop.jpg" />
      <ItemDry ItemDryId="77" ItemDryName="Neutrogena Naturals Lip Balm"
               ItemDryLink="http://www.somalystore.com/?product=neutrogena-naturals-lip-balm"
               ItemDryImage="images/NT069.JPG" />
      <ItemDry ItemDryId="78" ItemDryName="Neutrogena Revitalizing Lip Balm SPF 20, Healthy Blush 20"
               ItemDryLink="http://www.somalystore.com/?product=neutrogena-revitalizing-lip-balm-spf-20-healthy-blush-20"
               ItemDryImage="images/NT070.JPG" />
      <ItemDry ItemDryId="79" ItemDryName="Maybelline Baby Lips Moisturizing Lip Balm Lip Renewal"
               ItemDryLink="http://www.somalystore.com/?product=maybelline-baby-lips-moisturizing-lip-balm-lip-renewal"
               ItemDryImage="images/ML052-QUENCHED.jpg" />
      <ItemDry ItemDryId="80" ItemDryName="Boots No7 Protect &amp; Perfect Lip Cream"
               ItemDryLink="http://www.somalystore.com/?product=boots-no7-protect-perfect-lip-cream"
               ItemDryImage="images/BO040.JPG" />
      <ItemDry ItemDryId="81" ItemDryName="Eucerin Aquaphor Lip Repair + Protect, Broad Spectrum SPF 30"
               ItemDryLink="http://www.somalystore.com/?product=aquaphor-lip-repair-protect-broad-spectrum-spf-30"
               ItemDryImage="images/EU007.JPG" />
      <ItemDry ItemDryId="82" ItemDryName="Jane Iredale Lipdrink SPF 15 Lip Balm"
               ItemDryLink="http://www.somalystore.com/?product=jane-iredale-lipdrink-spf-15-lip-balm"
               ItemDryImage="images/BP014.jpg" />
      <ItemDry ItemDryId="83" ItemDryName="bliss Fabulips Sugar Lip Scrub"
               ItemDryLink="http://www.somalystore.com/?product=bliss"
               ItemDryImage="images/BP333.jpg" />
      <ItemDry ItemDryId="84" ItemDryName="Danny Seo Wholearth Lip Scrub &amp; Balm 2-in-1"
               ItemDryLink="http://www.somalystore.com/?product=danny-seo"
               ItemDryImage="images/BP334.jpg" />
      <ItemDry ItemDryId="85" ItemDryName="Sara Happ Vanilla Bean Lip Scrub-Vanilla Bean-1"
               ItemDryLink="http://www.somalystore.com/?product=sara-happ"
               ItemDryImage="images/BP335.1.png" />
  </DryCategory>

</ProductsDry>

这是我的&#34;产品列表.xaml.cs&#34;班级

private void lst_product_Loaded(object sender, RoutedEventArgs e)
{
    MessageBox.Show(pro_cate_id);
    XDocument data = XDocument.Load("All Files/Database XML/ProductsDry.xml");
    var productListData = from q in data.Descendants("DryCategory")
                          where q.Attribute("DryCategoryId").Value == pro_cate_id
                          select new ProductsDry
                          {
                              ItemDryName = q.Element("ItemDry").Attribute("ItemDryName").Value

                          };

    lst_product.DataContext = productListData;

}

这是我的xaml文件&#34;产品列表.xaml&#34;

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
     <ListBox Height="553" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="6,23,0,0" x:Name="lst_product" VerticalAlignment="Top" Width="444" Loaded="lst_product_Loaded">
         <ListBox.ItemTemplate>
             <DataTemplate>
                 <StackPanel Width="370">
                     <TextBlock x:Name="product_list_name" Text="{Binding ItemDryName}" FontWeight="Bold" FontSize="22"  />
                 </StackPanel>
             </DataTemplate>
         </ListBox.ItemTemplate>
     </ListBox>
 </Grid>

1 个答案:

答案 0 :(得分:0)

您可以使用两次from来访问所需ItemDry元素的所有DryCategory个孩子:

var productListData = from q in data.Descendants("DryCategory")
                      from itemDry in q.Elements("ItemDry")
                      where q.Attribute("DryCategoryId").Value == pro_cate_id
                      select new ProductsDry
                      {
                          ItemDryName = itemDry.Attribute("ItemDryName").Value
                      };