×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    11

    listbox returning same data from xml.

    im having problems showing data from my xml to my listbox with 2 textblocks.

    my xml looks like this:
    Code:
    <?xml version="1.0"  ?>
    <book>
    	<article
    	id="1"
    	articleno="i"
    	title="Introduction"
    	section=""
    	content="Content here..."
    	/>
    	<article
    	id="2"
    	articleno="p"
    	title="Preamble"
    	section=""
    	content="Content here..."
    	/>
    	<article
    	id="3"
    	articleno="1"
    	title="Scope and Limitations"
    	section="Section 1"
    	content="Section 1. Content here..."
    	/>
    	<article
    	id="4"
    	articleno="1"
    	title="Scope and Limitations"
    	section="Section 2"
    	content="Section 2. Content here..."
    	/>
    </book>
    then my code...
    Code:
    XDocument data = XDocument.Load("book.xml");
                var filteredData = from c in data.Descendants("article")
                                   where c.Attribute("articleno").Value == "1"
                                   select new Book()
                                   {
                                      ArticleNo = c.Attribute("articleno").Value,
                                      Title = c.Attribute("title").Value,
                                      Section = c.Attribute("section").Value,
                                      Content = c.Attribute("content").Value
                                   };
                
                listContents1.ItemsSource = filteredData;
    and my xaml..
    Code:
    <ListBox x:Name="listContents1" Grid.Row="1" Height="600">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                            <StackPanel Height="auto" HorizontalAlignment="Left" Margin="12,0,0,12" Name="stackPanel2" VerticalAlignment="Top" Width="444" Grid.Row="1">
                            <TextBlock Height="auto" Name="txSection" Text="{Binding Section}" FontSize="36" Margin="0,0,0,0" Foreground="White" />
                            <TextBlock Height="auto" Name="txContent" Text="{Binding Content}" Style="{StaticResource PhoneTextSubtleStyle}" Margin="0,0,0,0" TextTrimming="WordEllipsis" />
                            </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
    on this one.. its supposed to show the last 2 data in my xml.. but instead its showing the last data in my xml 2 times.

    kinda like:
    section 1.
    section 2.

    but instead im getting:
    section 2.
    section 2.

    i really dont see the problem.. could it bee in my xaml? my query in my linq is correct (i think)
    please help. thanks.

  2. #2
    Nokia Developer Champion
    Join Date
    Aug 2008
    Location
    Vadodara, India.
    Posts
    910

    Re: listbox returning same data from xml.

    I couldnt see any problem in your code before testing code. but I suggest you to check out below related links and take it as reference.

    http://www.developer.nokia.com/Commu...rom_XML_in_WP7
    http://www.windowsphonegeek.com/tips...nd-databinding

    Chintan.
    Nokia Developer Wiki Moderation team
    World's Greatest Speeches for Windows Phone is now available on WP Marketplace.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    11

    Re: listbox returning same data from xml.

    for real? i dont know. but mine is showing the last data repeatedly when its supposed to show all the data based on my query. and the tutorial on windows phone geek is the one i followed.
    thanks for the help though. much appreciated

  4. #4
    Nokia Developer Champion
    Join Date
    Aug 2008
    Location
    Vadodara, India.
    Posts
    910

    Re: listbox returning same data from xml.

    okay.. Something must went wrong though we can not find it in your code yet.

    Try to download source code from that tutorial and test.. Also try to debug you code. that's the easy way to troubleshoot.

    Chintan.
    Nokia Developer Wiki Moderation team
    World's Greatest Speeches for Windows Phone is now available on WP Marketplace.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1

    Re: listbox returning same data from xml.

    i have this problems too


    att

  6. #6
    Nokia Developer Champion
    Join Date
    May 2012
    Location
    UK
    Posts
    13

    Re: listbox returning same data from xml.

    Do you have a comnplete reproduction for the issue? I dropped the snippets below into an app and it all worked as expected. (I just created an empth `Book` class and added string auto properties for everything.)
    The LINQ statement works as intended, so it must be something else that isn't shown.

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    927

    Re: listbox returning same data from xml.

    On this line of code:
    listContents1.ItemsSource = filteredData;
    Place a breakpoint.

    When running your app, select filteredData, left click and select quick watch. Browse the collection and make sure that the data that you have in there is what you are expecting.

    If its correct then there must be something else because I dont see anything wrong with your code from reading it. So if you can provide a project file with a sample of the behavior I can try and reproduce it.

  8. #8
    Registered User
    Join Date
    Feb 2012
    Posts
    11

    Re: listbox returning same data from xml.

    okay. i found out whats causing it. apparently i have a class that contains global variables. and im pretty sure that the global variables are being the one displayed on my listbox thats why the data are just being repeated. i removed my global variables and just made local variables to my Book class and it worked just like in the tutorial. thanks for everyone who replied to this thread.

Similar Threads

  1. Replies: 2
    Last Post: 2011-10-05, 10:04
  2. Read Data from Listbox.
    By Kavit Patel in forum Symbian
    Replies: 2
    Last Post: 2008-02-02, 12:23
  3. ListBox ( no data )
    By sohilr in forum Symbian User Interface
    Replies: 2
    Last Post: 2007-12-08, 07:14
  4. ListBox with additional data
    By krzysiekj in forum Symbian
    Replies: 5
    Last Post: 2007-11-26, 13:54
  5. ListBox...Data not appearing..Please HELP!:)
    By flipflop82 in forum Symbian
    Replies: 2
    Last Post: 2005-03-04, 12:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×