1
votes

I am building a WP8 app. On the initial page of my app (after login), I am using the GestureService to manipulate the screen and create the effect of a slideout menu. This is all fine, but the problem is the GestureService is activated whenever a swipe action is performed on ListPicker controls on ANY other page of the app, and throws an unhandled Object reference not set exception, like so:

enter image description here

I've done some digging and this appears to be a bug within the WP Toolkit. The behaviour is the same on both the WP8 emulator and the Nokia WP8 dev phone I am using. According to this thread, I can use the ManipulationDelta and ManipulationCompleted events to achieve the same thing the GestureListener does. So I commented out the GestureService code and added Manipulation events onto the grid on my main page. Low and behold, the problem has disappeared.

Here is the GestureService call (on my initial xaml page), which is now commented out:

<toolkit:GestureService.GestureListener>
            <toolkit:GestureListener DragDelta="GestureListener_OnDragDelta" DragCompleted="GestureListener_OnDragCompleted" />
        </toolkit:GestureService.GestureListener>

The problem I am now facing is translating the code into the new format. Here is the Gesture code I am using (in VB):

If e.Direction = System.Windows.Controls.Orientation.Horizontal AndAlso e.HorizontalChange > 0 AndAlso Not _isSettingsOpen Then
            Dim offset As Double = _feContainer.GetHorizontalOffset().Value + e.HorizontalChange
            If offset > _dragDistanceToOpen Then
                Me.OpenSettings()
            Else
                _feContainer.SetHorizontalOffset(offset)
            End If
        End If

        If e.Direction = System.Windows.Controls.Orientation.Horizontal AndAlso e.HorizontalChange < 0 AndAlso _isSettingsOpen Then
            Dim offsetContainer As Double = _feContainer.GetHorizontalOffset().Value + e.HorizontalChange
            If offsetContainer < _dragDistanceToClose Then
                Me.CloseSettings()
            Else
                _feContainer.SetHorizontalOffset(offsetContainer)
            End If
        End If

Not all the properties in the GestureListener are available/ comparable to the Manipulation events.

So am I best off soldiering on and attempting to recreate the effect within the Manipulation (if it's even possible), or does anyone know of a better way of doing this; i.e. a way of fixing or circumventing the bug to allow the GestureService to work...?

I already tried adding the GestureListener code and empty Try Catch statements to the pages with ListPicker controls on them, but it didn't solve the problem.

On another (related) note, I can avoid the error by simply setting the exception to Handled in App.Xaml. There is still an unhandled exception there, I'm just ignoring it. Is this behaviour likely to cause my app to be rejected from the store?

Any help is appreciated.

1

1 Answers

1
votes

Ok, so low views and no replies to this for almost a week, so here's my temorary fix for anyone finding this via Google.

In the app.xaml, I simply stopped unhandled exceptions from displaying messages to the user:

Public Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles Me.UnhandledException
        ' Show graphics profiling information while debugging.
        If Diagnostics.Debugger.IsAttached Then
            'There is a bug in the WP Toolkit which throws an unhandled exception when GestureListener events are used within the app,
            'and a ListPicker control is swiped over. Altering this method ignores these exceptions.

            'Diagnostics.Debugger.Break()
            e.Handled = True

        Else
            e.Handled = True
            'MessageBox.Show(e.ExceptionObject.Message & Environment.NewLine & e.ExceptionObject.StackTrace,
            '                "Error", MessageBoxButton.OK)
        End If
    End Sub

This is certainly not an ideal soultion, but is the only thing I could come up with in place of spending countless hours trying to circumvent the Toolkit bug. It's been a while since the last release, so hopefully it will be fixed in the next one. I'll edit this answer if that happens, or if this fix prevents the app from entering the store.

EDIT: App was submitted to the store successfully, so although not a perfect solution, it will do the job.