-
Jul 10th, 2017, 08:35 AM
#1
Thread Starter
Addicted Member
UWP - Back Button Problems with Pivot Tables
Afternoon all,
I've got a bit of an odd problem that I can't seem to get to the bottom off. The back button works perfectly unless I'm in a Pivot table, where it will jump clean out of the pivot tabel and back to the previous page. What I would like to happen is to go back to the previous page or previous pivot table page... Any Idea how I might be able to achieve this...?
Thanks
Dave
-
Jul 10th, 2017, 08:53 AM
#2
Re: UWP - Back Button Problems with Pivot Tables
Afternoon Dave,
I reckon you're going to have to show us what you're doing before we can offer any help.
We need to at least see the code where the problem is.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Jul 10th, 2017, 09:14 AM
#3
Thread Starter
Addicted Member
Re: UWP - Back Button Problems with Pivot Tables
I thought you might ask that...
This code makes the back button work:
App.xaml.vb
Code:
'The Event Handler:
AddHandler SystemNavigationManager.GetForCurrentView().BackRequested, AddressOf OnBackRequested
'The Procedure that does the work:
Private Sub OnBackRequested(sender As Object, e As BackRequestedEventArgs)
Dim rootFrame As Frame = TryCast(Window.Current.Content, Frame)
If rootFrame.CanGoBack Then
e.Handled = True
rootFrame.GoBack()
End If
End Sub
This is the code that goes to a previous pivot page
BookingPage.XAML.VB
Code:
Private Sub PreviousPivotPage()
If rootpivot.SelectedIndex >= 1 And rootpivot.SelectedIndex <= rootpivot.Items.Count Then
rootpivot.SelectedIndex = rootpivot.SelectedIndex - 1
End If
End Sub
Edit: Just noticed I posted in the wrong forum, I think it should be in 'Modern Windows Experience', if you want to move it pls feel free...
Last edited by QuattroDave; Jul 10th, 2017 at 09:42 AM.
Reason: info
-
Jul 11th, 2017, 06:40 AM
#4
Re: UWP - Back Button Problems with Pivot Tables
I think this will do what you want (assuming rootpivot is in scope):
Code:
Private Sub OnBackRequested(sender As Object, e As BackRequestedEventArgs)
If rootpivot.SelectedIndex >= 1 And rootpivot.SelectedIndex <= rootpivot.Items.Count Then
rootpivot.SelectedIndex = rootpivot.SelectedIndex - 1
Else
Dim rootFrame As Frame = TryCast(Window.Current.Content, Frame)
If rootFrame.CanGoBack Then
e.Handled = True
rootFrame.GoBack()
End If
End If
End Sub
 Originally Posted by QuattroDave
Edit: Just noticed I posted in the wrong forum, I think it should be in 'Modern Windows Experience', if you want to move it pls feel free...
Moved
-
Jul 11th, 2017, 08:25 AM
#5
Thread Starter
Addicted Member
Re: UWP - Back Button Problems with Pivot Tables
Hi Si,
Thanks for the reply & thanks for moving the post. Thats the problem, the pivot table isn't in the scope of 'App.xaml.vb' really not sure how to get around this. Can I expand the scope or am I able to override the handeling of the back button...?
Thanks
Dave
-
Jul 11th, 2017, 02:54 PM
#6
Re: UWP - Back Button Problems with Pivot Tables
I've only briefly looked into UWP, so I'm not sure of how it all works.
Assuming that the pivot table is an object on the page, you might be able to declare a public variable of the same data type, then inside the page with the pivot table assign that pivot table to the variable - which you can then use in the Back routine.
-
Jul 12th, 2017, 10:20 AM
#7
Thread Starter
Addicted Member
Re: UWP - Back Button Problems with Pivot Tables
Thanks for your reply,
I'm sturggeling to understand how that would work and how I'd code it, have you got any examples you can point me to?
I also came accross this in C# a little earlier but don't seem to be able to translate it to VB, any ideas?
https://stackoverflow.com/questions/...set-in-appx-cs
Many thanks
Dave
-
Jul 13th, 2017, 07:21 AM
#8
Thread Starter
Addicted Member
Re: UWP - Back Button Problems with Pivot Tables
After a bit more reading and head scratching I think this is exactly what I need:
https://stackoverflow.com/questions/...set-in-appx-cs
In C#
App.xaml.cs:
Code:
public event EventHandler<BackRequestedEventArgs> BackRequested;
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
// Raise child event
var eventHandler = this.BackRequested;
if (eventHandler != null)
{
eventHandler(sender, e);
}
if (!e.Handled)
{
if (_rootFrame != null && _rootFrame.CanGoBack)
{
e.Handled = true;
_rootFrame.GoBack();
}
}
}
Then in your page, subscribe to the child event instead of the main one:
Code:
((App)(App.Current)).BackRequested += OnBackRequested;
Make sure to unsubscribe to the event when leaving the page, or you may end up with a memory leak.
I've managed to convert most of it to VB:
Code:
Public Event BackRequested As EventHandler(Of BackRequestedEventArgs)
Private Sub OnBackRequested(sender As Object, e As BackRequestedEventArgs)
' Raise child event
RaiseEvent BackRequested(sender, e)
If Not e.Handled Then
If _rootFrame IsNot Nothing AndAlso _rootFrame.CanGoBack Then
e.Handled = True
_rootFrame.GoBack()
End If
End If
End Sub
But I'm really struggeling with this line:
Code:
((App)(App.Current)).BackRequested += OnBackRequested;
Any pointers as to how it should be in VB?
Thanks
Dave
-
Jul 13th, 2017, 08:00 AM
#9
Re: UWP - Back Button Problems with Pivot Tables
I think it should be this:
Code:
AddHandler App.Current.BackRequested, AddressOf OnBackRequested
-
Jul 13th, 2017, 10:41 AM
#10
Thread Starter
Addicted Member
Re: UWP - Back Button Problems with Pivot Tables
Thanks for the reply Si,
Hmmm it doesn't recognise 'App' so I'm going to assume 'Application' would be the correct choice. but then on this line:
Code:
AddHandler Application.Current.BackRequested, AddressOf OnBackRequested
I get the error 'BackRequested' is not a member of 'Application' when its blatently declaired there...
Why is it the small issues that cause all the problems 
Thanks
Dave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|