If you're not too distracted by all the announcements coming from MWC at the moment I thought I'd share this little gotcha that cost me more time than it should have.
I'm updating an app for a client at the moment and for one of the visual tweaks that I wanted to add meant I wanted to replace a ListBox with a LongListSelector.
All should be simple enough. It should just be a case of replacing this:
with this:
All seemed good but then no items were shown on the page.
Huh!?
Why?!
Well, it turns out that in the ViewModel the Sessions property was an IEnumerable<Session>.
For the LongListSelector to be able to load the items it needs the NotifyPropertyChanged events to be raised. The easiest way to do this was to change the Sessions property to be an ObservableCollection<Session>. This way the necessary events are raised and content is displayed. :)
Obvious really.
Hopefully this reminder will save someone else some head scratching in future.
I'm updating an app for a client at the moment and for one of the visual tweaks that I wanted to add meant I wanted to replace a ListBox with a LongListSelector.
All should be simple enough. It should just be a case of replacing this:
<ListBox ItemsSource="{Binding Sessions}"> <ListBox.ItemTemplate> <DataTemplate> // ... </DataTemplate> </ListBox.ItemTemplate> </ListBox>
with this:
<phone:LongListSelector ItemsSource="{Binding Sessions}"> <phone:LongListSelector.ItemTemplate> <DataTemplate> // ... </DataTemplate> </phone:LongListSelector.ItemTemplate> </phone:LongListSelector>
All seemed good but then no items were shown on the page.
Huh!?
Why?!
Well, it turns out that in the ViewModel the Sessions property was an IEnumerable<Session>.
For the LongListSelector to be able to load the items it needs the NotifyPropertyChanged events to be raised. The easiest way to do this was to change the Sessions property to be an ObservableCollection<Session>. This way the necessary events are raised and content is displayed. :)
Obvious really.
Hopefully this reminder will save someone else some head scratching in future.