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>[/CODE]
The ListBox is data bound from code behind by doing this:
[CODE] lbCurrentTickets.ItemsSource = events;[/CODE]
'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" />[/CODE]
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: [URL="http://bit.ly/MyWPApps"]http://bit.ly/MyWPApps[/URL]
Re: ListBox DataBinding issue in WP 7.5
Is your class Event set to public?
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; }
}[/CODE]
Re: ListBox DataBinding issue in WP 7.5
as WPMorocco stated try setting you class to public
[CODE][B]public [/B]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; }
}[/CODE]
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; }
}
[/CODE]
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?