1

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.

Gabor
  • 1,656
  • 1
  • 16
  • 28
  • Not sure, I'm no WinPhone developer, but `ItemsSource="{Binding EventData}"`, should it not be `ItemsSource="{Binding Path=EventData}"`? – Sjips Nov 06 '14 at 12:21
  • Thanks for the comment, but there is no difference in semantics between the two notations (see http://stackoverflow.com/questions/4306657/difference-between-binding-propertyname-and-binding-path-propertyname). 'Path' is the default property so it can be omitted. – Gabor Nov 06 '14 at 12:29
  • Create [domain level exception logging](http://stackoverflow.com/a/21530177/1997232) (this is for winforms, search one for wpf, to example, [here](http://stackoverflow.com/q/1472498/1997232)) and look into inner exception. – Sinatr Nov 06 '14 at 12:37
  • Yes, you're right. I did a WPF desktop app in the past and I remembered that these kind of errors are sometimes in the details. But are you sure you get 6 items or more from `var geoFenceEvents = await AppCacheSimple.GetItemsAsync...`? I'm not sure if `...Take(6)` will throw exception if there are less items. – Sjips Nov 06 '14 at 12:38
  • Ok, that stuff is only there for debugging -- in a rather desperate fashion. Currently the first line (`var geoFenceEvents = await AppCacheSimple.GetItemsAsync...`) always returns 8 items. The goal is to just have `_eventData.AddRange(geoFenceEvents)`, and have the ListView display them correctly regardless of the number of items (am not expecting more than say 100 items though). – Gabor Nov 06 '14 at 13:38
  • Thanks, for the links regarding exception logging, I will give that a try -- although I my understanding is that VS subscribes for all UnhandledException in the AppDomain during a debug session, so am afraid this is one of those rare exceptions that dont raise this event, just crash the app. – Gabor Nov 06 '14 at 13:45
  • You said "VS does not realize the app was shut down". I've had the same problem, but after 30 seconds or so, there was some info in the Output window "app exited with code xxxx". See if something comes up if you wait a little. Also, could you try to dispatch the `Clear` and `AddRange` calls to the UI thread? I know it sounds pointless, try it anyway. – yasen Nov 06 '14 at 13:57
  • just FYI, I'm facing the same issue 'sometimes' and I'm using HTML/Javascript... I guess it's a Windows Runtime issue???? Could it be possible that both controls have the same bug (behavior)? – sebagomez Nov 06 '14 at 15:00

0 Answers0