Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:11:37+00:00 2026-06-01T21:11:37+00:00

I am writing a windows phone 7 app and i have an xml file

  • 0

I am writing a windows phone 7 app and i have an xml file which looks like this

    <Barcodes>
  <Barcode code="7393997155338"
           companyName="Garbo Food AB"
           productName="Toast Loaf"/>

</Barcodes>

I am searching the xml file using xElement like below, i am getting not null on the listbox which says to me its populated?!?

        var searchElement = XElement.Load("storedBarcodes.xml");
        var barcodeProductResult = from var in searchElement.Descendants("Barcodes") 
                                   where var.Attribute("code").Value == b
                                   select new ProductBarcodes()
                                   {
                                       code = var.Attribute("code").Value,
                                       companyName = var.Attribute("companyName").Value,
                                       productName = var.Attribute("productName").Value

                                   };
        if (barcodeProductResult != null)
        {
            tbSuccessfullSearchOrNot.Text = ("Search has found a matching product!");

            if (resultsListBox != null)
            {

                resultsListBox.ItemsSource = barcodeProductResult;
                tbSuccessfullSearchOrNot.Text = ("Search has found a matching product! but listbox is not empty");
            }
            else
            {

                tbSuccessfullSearchOrNot.Text = ("Search has found a matching product! but listbox is empty");
            }
                //tbProductBarcode.Text = ("Product Barcode : " + _code + Environment.NewLine);
            //tbCompanyName.Text = ("Company Name: " + _companyName + Environment.NewLine);
        }
        else
        {
            tbSuccessfullSearchOrNot.Text = ("No matching product found!");
        }

and after the listbox is populated it should be output on the screen like below, I am trying a couple of ways ie. using {Binding Path=Element[code].Value}”, and just Text=”{Binding code}, the result is empty on output screen,

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <StackPanel>
        <Button Height="150" Content="Press here to scan a barcode !!" Click="Button_Click" Foreground="#FF2FFF07" />
        <TextBlock Margin="30" FontSize="36" TextWrapping="Wrap"   x:Name="tbSuccessfullSearchOrNot"/>
        <TextBlock Margin="30" FontSize="36" TextWrapping="Wrap"   x:Name="tbScanResultBarCode"/>
        <ListBox x:Name="resultsListBox" TabIndex="8" ItemsSource="barcodeProductResult" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="10" >
                        <TextBlock x:Name="results" Text="{Binding code}"   FontSize="22" FontWeight="Bold" FontStyle="Italic" Foreground="Orange"  />
                        <TextBlock Text="{Binding Path=Element[code].Value}" Foreground="Black"/>
                        <TextBlock Text="{Binding companyName}" Foreground="Black"/>
                        <TextBlock Text="{Binding productName}" Foreground="Black"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <!--<TextBlock Height="346" FontSize="36" x:Name="tbProductDetails" TextWrapping="Wrap"  Width="450" >

        </TextBlock>-->
        <TextBox Height="71" Name="tbProductBarcode"  Width="460" IsEnabled="False" IsReadOnly="True" DataContext="{Binding ElementName=tbProductBarcode}" />
        <TextBox Height="71" Name="tbCompanyName"  Width="460" IsEnabled="False" IsReadOnly="True" />
        <TextBox Height="71" Name="tbProductName"  Width="460" IsEnabled="False" IsReadOnly="True" />
        <!--<Button Height="150" Content="Tap to scan a QR code" Click="Button_Click_1"/>
        <TextBlock Margin="30" FontSize="36" TextWrapping="Wrap" x:Name="tbScanResultQR"/>-->

    </StackPanel>
</Grid>

Post Edit:
This is the code im basing my search on. This works,

       private void menuBtn_Click(object sender, RoutedEventArgs e)
    {
        var element = XElement.Load("SearchFile.xml");
        var filteredData = from var in element.Descendants("chipper")
                           where var.Attribute("County").Value.ToLower()==tbSearch.Text.ToLower() 
                           select new Counties()
                           {
                               LName = var.Attribute("LName").Value,
                               PlAddress = var.Attribute("PlAddress").Value,
                               County= var.Attribute("County").Value,
                               PhoneNumber = var.Attribute("PhoneNumber").Value


                           };

        ChipperListBox.ItemsSource = filteredData;
    }

and the xaml:

  <StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,90" Orientation="Horizontal">
    <ListBox x:Name="ChipperListBox" SelectionChanged="listBox_SelectionChanged">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="10" >
                    <TextBlock x:Name="chipName" Text="{Binding LName}"   FontSize="22" FontWeight="Bold" FontStyle="Italic" Foreground="Orange" Tap="chipName_Tap" />
                    <TextBlock Text="{Binding PlAddress}" Foreground="Black"/>
                    <TextBlock Text="{Binding County}" Foreground="Black"/>
                    <TextBlock Text="{Binding PhoneNumber}" Foreground="Black"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</StackPanel>

EDIT: I un this app on a windows phone because the emulator has no camera.heres the info from call stack after changing the element name to “Barcode” i get a readerException which stops the barcode scanner almost instantly but when i stop debugging i run again outside visual studio just on the phone and the app runs but still no output to the listbox in the xaml

“A first chance exception of type ‘com.google.zxing.ReaderException’
occurred in Silverlight_ZXing_Core.dll

Additional information: ReaderException”

Silverlight_ZXing_Core.dll!com.google.zxing.oned.UPCEANReader.findGuardPattern(com.google.zxing.common.BitArray row, int rowOffset, bool whiteFirst, int[] pattern) + 0xf1 bytes    
    Silverlight_ZXing_Core.dll!com.google.zxing.oned.UPCEANReader.findStartGuardPattern(com.google.zxing.common.BitArray row) + 0x8 bytes   
    Silverlight_ZXing_Core.dll!com.google.zxing.oned.UPCEANReader.decodeRow(int rowNumber, com.google.zxing.common.BitArray row, System.Collections.Generic.Dictionary<object,object> hints)    
    Silverlight_ZXing_Core.dll!com.google.zxing.oned.OneDReader.doDecode(com.google.zxing.BinaryBitmap image, System.Collections.Generic.Dictionary<object,object> hints) + 0x113 bytes 
    Silverlight_ZXing_Core.dll!com.google.zxing.oned.OneDReader.decode(com.google.zxing.BinaryBitmap image, System.Collections.Generic.Dictionary<object,object> hints) 
    Silverlight_ZXing_Core.dll!com.google.zxing.oned.OneDReader.decode(com.google.zxing.BinaryBitmap image) + 0x3 bytes 
>   WP7.ScanBarCode.dll!WP7.ScanBarCode.BarCode.cam_AutoFocusCompleted(object sender, Microsoft.Devices.CameraOperationCompletedEventArgs e) Line 114 + 0x7 bytes   C#
    Microsoft.Phone.dll!Microsoft.Devices.Camera.SafeFireEvent<Microsoft.Devices.CameraOperationCompletedEventArgs>.AnonymousMethod__1f(object ignored) + 0x17 bytes    
    mscorlib.dll!System.Threading.ThreadPool.WorkItem.WaitCallback_Context(object state) + 0x18 bytes   
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x63 bytes    
    mscorlib.dll!System.Threading.ThreadPool.WorkItem.doWork(object o) + 0x47 bytes 
    mscorlib.dll!System.Threading.Timer.ring() + 0x70 bytes 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:11:39+00:00Added an answer on June 1, 2026 at 9:11 pm

    Barcodes is your root element and you want a list of Barcode items, so use this as your from:

    from barcode in searchElement.Descendants("Barcode")
    

    As a side note, your null checks aren’t correct. barcodeProductResult will not be null, but it might have a Count() of 0. resultsListBox will also never be null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a windows phone 7 app. I have fatal exception handling code where
I'm writing a windows phone app and I would like to implement a tap
I'm writing an App for Windows Phone in XNA... and I'd like to read
We're developing a Windows Phone 7 app and have a TextBlock defined like so:
I'm writing a Windows Phone Mango app. I have a hyperlink that contains email
I'm writing a Windows Phone app in C#. I have a setting OrientationLock that
I'm writing a Windows Phone 7 App and would like to be able to
I'm writing a windows phone app which stores data in a local database. There
I'm writing a windows phone app that consist of a pivot control, and I
I'm writting a Windows Phone App, in the GUI a have a listbox with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.