×

Discussion Board

Results 1 to 6 of 6

Hybrid View

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

    Exclamation ListBox DataBinding issue in WP 7.5

    I recently wrote an app targeting WP 7.1 SDK which uses a ListBox and DataBinds it from code behind. When I run this app on a WP8 device or a WP8 emulator, the app works fine and I can see the data on the page. But when this exact same app is run on a WP7.5 device or emulator, the ListBox does not show any data. I have not been able to figure out why for the life of me!

    Here is the ListBox in XAML:

    Code:
                        <ListBox Name="lbCurrentTickets" SelectionChanged="lbCurrentTickets_SelectionChanged" Margin="10,10,0,0">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=StartDate}" Margin="0,15,0,0" FontWeight="ExtraBold" Foreground="Black" />
                                        <TextBlock Text="{Binding Path=Title}" Margin="0,-5,0,0" FontSize="30" Foreground="#3A87D3" />
                                        <TextBlock Text="{Binding Path=Address}" Margin="0,-5,0,0" FontSize="22" Foreground="Gray" Visibility="{Binding ShowAddressField}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
    The ListBox is data bound from code behind by doing this:

    Code:
                    lbCurrentTickets.ItemsSource = events;
    'events' is an object of a class, and I have verified that it does contain all the right data at this point. When this code is run on a WP7.5 device the ListBox shows up empty even though it is bound with actual data, but when this exact code is run on a WP8 device it shows the data perfectly fine.

    Just for testing sake I hardcoded one of the TextBlocks inside the ListBox with a value, like:

    Code:
                                        <TextBlock Text="This is a test" Margin="0,-5,0,0" FontSize="30" Foreground="#3A87D3" />
    and the text "This is a test" shows up the right number of times (the number of items in the 'events' object) which means the ListBox is being data bound somewhat properly.

    Can someone help resolve this issue as to why the ListBox displays empty when I run this code on a WP7.5 device?

    To summarize, this WP7.1 app works fine on a WP8 device but not on a WP7.5 device.

    Regards,
    Paras Wadehra
    My WP Apps: http://bit.ly/MyWPApps

  2. #2
    Regular Contributor
    Join Date
    Jul 2012
    Posts
    88

    Re: ListBox DataBinding issue in WP 7.5

    Is your class Event set to public?

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    5

    Re: ListBox DataBinding issue in WP 7.5

    It is as follows:
    Code:
        class EventSummary
        {
            public string ID { get; set; }
            public String StartDate { get; set; }
            public String Title { get; set; }
            public String Address { get; set; }
            public String Categories { get; set; }
            public string BarcodeID { get; set; }
            public string AttendeeName { get; set; }
            public string ShowAddressField { get; set; }
        }

  4. #4
    Regular Contributor
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    298

    Re: ListBox DataBinding issue in WP 7.5

    as WPMorocco stated try setting you class to public

    Code:
    public class EventSummary
        {
            public string ID { get; set; }
            public String StartDate { get; set; }
            public String Title { get; set; }
            public String Address { get; set; }
            public String Categories { get; set; }
            public string BarcodeID { get; set; }
            public string AttendeeName { get; set; }
            public string ShowAddressField { get; set; }
        }

  5. #5
    Regular Contributor
    Join Date
    Jul 2012
    Posts
    88

    Re: ListBox DataBinding issue in WP 7.5

    try with :
    Code:
    public class EventSummary
        {
            public string ID { get; set; }
            public String StartDate { get; set; }
            public String Title { get; set; }
            public String Address { get; set; }
            public String Categories { get; set; }
            public string BarcodeID { get; set; }
            public string AttendeeName { get; set; }
            public string ShowAddressField { get; set; }
    }

  6. #6
    Super Contributor
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    581

    Re: ListBox DataBinding issue in WP 7.5

    How and when you Bind data to a control matters. If the control hasn't full initialised, then data might not appear.

    When is your code being run? in the page constructor or in OnNavigatedTo?

    Also, are your 'events' being stored in a List or ObservableCollection?

Similar Threads

  1. Listbox Issue
    By nisheethpandey in forum Symbian
    Replies: 4
    Last Post: 2009-12-14, 11:22
  2. Listbox Issue
    By mastermindcoders in forum Symbian User Interface
    Replies: 4
    Last Post: 2009-08-25, 07:52
  3. Xml DataBinding sis file
    By george0095 in forum Series 40 & S60 Platform Feedback Archive
    Replies: 4
    Last Post: 2008-10-15, 15:10
  4. ListBox issue
    By songoku83 in forum Symbian
    Replies: 5
    Last Post: 2008-02-06, 13:22
  5. Yet another listbox issue
    By larsoveclaesson in forum Symbian User Interface
    Replies: 1
    Last Post: 2005-07-28, 08:40

Posting Permissions

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