UWP - Back Button Problems with Pivot Tables-VBForums
Results 1 to 10 of 10

Thread: UWP - Back Button Problems with Pivot Tables

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    175

    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

  2. #2
    Frenzied Member Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Near Barnsley South Yorkshire, England.
    Posts
    1,384

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    175

    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 10:42 AM. Reason: info

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,379

    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

    Quote Originally Posted by QuattroDave View Post
    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    175

    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

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,379

    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.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    175

    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    175

    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

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,379

    Re: UWP - Back Button Problems with Pivot Tables

    I think it should be this:
    Code:
    AddHandler App.Current.BackRequested, AddressOf OnBackRequested

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    175

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.