My list is the only element in a HubSection. It is defiened by the following DataTemplate:
<!-- List -->
<DataTemplate x:Key="GeofenceEventsList" >
<ListView ItemsSource="{Binding EventData}" SelectionMode="None" IsSwipeEnabled="False"
IsItemClickEnabled="False" ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemTemplate="{StaticResource GeofenceEventsListItem}" />
</DataTemplate>
The GeofenceEventsListItem
datatemplate is simple: a Grid
with 3 rows, where each has a text block in it (the first row has 3 text blocks in a StackPanel
).
The ListView
is referred in the following Hub
:
<Hub x:Name="Container" Grid.Row="1" Background="{StaticResource AppBackground}"
HeaderTemplate="{StaticResource PageHeader}">
<HubSection HeaderTemplate="{StaticResource HubHeader}"
Header="Recent events"
DataContext="{Binding Path=GeofencesViewModel}"
ContentTemplate="{StaticResource GeofenceEventsList}" />
<HubSection HeaderTemplate="{StaticResource HubHeader}"
Header="Geofences"
DataContext="{Binding Path=GeofencesViewModel}"
ContentTemplate="{StaticResource GeofencesList}" />
<!-- Other HubSections... -->
</Hub>
The key parts of the ViewModel behind looks like:
//Constructor:
public GeofencesViewModel(FacebookDataProvider facebookDataProvider) : base(facebookDataProvider)
{
_eventData = new ObservableCollection<GeofenceEventSchema>();
}
//Property:
private readonly ObservableCollection<GeofenceEventSchema> _eventData;
public IEnumerable<GeofenceEventSchema> EventData
{
get
{
Debug.WriteLine("EventData queried.");
return _eventData;
}
}
public async Task OnNavigatedTo()
{
//...
var geoFenceEvents = await AppCacheSimple.GetItemsAsync<GeofenceEventSchema>(GeofenceEventSchema.CacheKey);
_eventData.Clear();
//ListView crashes when we take 6 or more items, and scrolling becomes neccessary
//The screen can fit 4.9 items
_eventData.AddRange(geoFenceEvents.Take(6));
//...
}
This is part of a Universal App run on WindowsPhone 8.1.
The app works just fine with 5 or less items in the ListView
.
With 6 items in the list the crash occurs, when I try scrolling the list. (Visual Studio cought a Windows.UI.Xaml.UnhandledException but debugging was impossible because the phone just shut down the app and VS froze.)
With 8 items in the list, the App immediately crashes after loading the page: VS cannot catch anything at all, it does not even realize that the App was shut down.