locked
How do I detect a snapped viewstate in Visual Basic 2012? RRS feed

  • Question

  • I created a sub but it is not automatically activated when I move the app into a snapped state.  How should I change this:

    Protected Sub onViewStateChanged(eventArgs)

    End Sub

    Saturday, August 10, 2013 3:00 AM

All replies

  • You can watch for the Window.SizeChanged from which you can identify the application's present ViewState. Please take a look at the sample here: http://code.msdn.microsoft.com/windowsapps/Snap-sample-2ff037ae

    - Ram
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, August 10, 2013 7:51 AM
  • hiiii

    you can try this code

    Public Sub OnSizeChanged(sender As Object, args As Windows.UI.Core.WindowSizeChangedEventArgs)
           Select Case Windows.UI.ViewManagement.ApplicationView.Value
                Case Windows.UI.ViewManagement.ApplicationViewState.Filled
                   VisualStateManager.GoToState(Me, "Filled", False)
                  Exit Select
               Case Windows.UI.ViewManagement.ApplicationViewState.FullScreenLandscape
                   VisualStateManager.GoToState(Me, "Full", False)
                   Exit Select
               Case Windows.UI.ViewManagement.ApplicationViewState.Snapped
                  VisualStateManager.GoToState(Me, "Snapped", False)
                    Exit Select
             Case Windows.UI.ViewManagement.ApplicationViewState.FullScreenPortrait
                    VisualStateManager.GoToState(Me, "Portrait", False)
                   Exit Select
               Case Else
                   Exit Select
            End Select
    
             Me.ShowCurrentViewState()
        End Sub
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpfull


    Er.Rasik Ambaliya

    Saturday, August 10, 2013 1:09 PM
  •   Public Sub OnSizeChanged(sender As Object, args As Windows.UI.Core.WindowSizeChangedEventArgs)
            Select Case Windows.UI.ViewManagement.ApplicationView.Value
               Case Windows.UI.ViewManagement.ApplicationViewState.Filled
                    VisualStateManager.GoToState(Me, "Filled", False)
                    Exit Select
                Case Windows.UI.ViewManagement.ApplicationViewState.FullScreenLandscape
                    VisualStateManager.GoToState(Me, "Full", False)
                    Exit Select
                Case Windows.UI.ViewManagement.ApplicationViewState.Snapped
                    VisualStateManager.GoToState(Me, "Snapped", False)
                    Exit Select
                Case Windows.UI.ViewManagement.ApplicationViewState.FullScreenPortrait
                    VisualStateManager.GoToState(Me, "Portrait", False)                Exit Select
               Case Else
                   Exit Select
           End Select
    
            Me.ShowCurrentViewState()
        End Sub

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpfull



    Er.Rasik Ambaliya

    • Proposed as answer by RasikAmbaliya Saturday, August 10, 2013 1:14 PM
    Saturday, August 10, 2013 1:13 PM
  • Thank you for the response, but I tried it and it doesn't work.  Your OnSizeChanged subroutine is not called when I change my app to "Snapped" or any other view-state.  Also, when I copy and paste your subroutine, the second-to-last line of code, "Me.ShowCurrentViewState()" does not compile.  I had to comment it out.

    I tried using:

    Private

    Sub Grid_SizeChanged(sender As Object, e As SizeChangedEventArgs)and that is activated when I change the resolution while the app is running.  So why would Grid_SizeChanged work and OnSizeChanged not respond to the event?  Please try again, because I think you are close to solving this, and I appreciate your help.
    Saturday, August 10, 2013 1:54 PM
  • I am unable to view this code sample.  The error message from Visual Studio says, "This edition of Visual Studio only supports Windows Store apps. "  Would you please cut-and-paste the code I need?  I have been trying to solve this for four days.
    Saturday, August 10, 2013 2:04 PM