windows silverlight app stuck on one page - c#

In my windows phone app I am doing a scanning process, wherever I am in the app, when the scan button is pressed on my bottom appbar, I navigate to my scan page, known as ScanView.xaml.
Problem:
I have overridden onnavigatedTo method of scanView to initiate scanning screen.
When I press back button while I am on the scanning screen It goes back to ScanView.xaml and hence onnavigatedTo method is again called and my scanning screen again appears.
What I want to do is, when I press back button while on scanning screen it should navigate directly back to my mainpage.xaml
P.S : I have tried overriding the backbutton handler, but it is still not working.
Here is my code.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//this method is invoked as soon as we are navited to the ScanView
Scanning();
}
Thanks in advance

Just remove ScanView.xaml from the navigation stack (it is the item at the top of the stack) when navigated to the scanning page.

Related

Xamarin Software Back Button Event

How can I fire an event when the software back button in the navigation bar is tapped?
I tried using the following code but this only works for a hardware back button.
protected override bool OnBackButtonPressed()
{
return true;
}
The OnBackButtonPressed is fired when you press the back button on the device. If you want to get backbutton event. You may need to create Custom Renderers for each platform. You can refer to the answer here Override nav bar back button click on Xamarin.Forms

How to notify the page when GoBack() happened?

Here is what my app does:
The first page can navigate to the second page, and the second page displays a list of data. The user can choose one of them then the app will bring the data back to the first page.
Sounds easy, but I'm confused with the Windows Mobile Navigation Model.
The first page navigates to the second page, using this code:
this.Frame.Navigate(typeof(SecondPage));
and the second page uses the code below to go back:
this.Frame.GoBack();
How could the first page know if the second page disappeared? I want to update the UI on the first page after the second page disappeared.
Now, I used a static class to keep the data that user picks, but I have no idea when should be the right time to update the first page.
Is there any way to get an event or notification?
This is quite simple, since UWP does this for you. I noticed you're not using MVVM, so you can simply override the OnNavigatedTo event in your page. This event is triggered when navigation to your page is completed (and thus the second screen dissapeared). Simply check for NavigationMode.Back to confirm you're returning and not navigating forward.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.NavigationMode == NavigationMode.Back)
{
// coming from 2nd page, so refresh your data
}
}

UWP Xbox One page navigation when using WebView

Usually when running a UWP app on Xbox the B button on the controller is handled automatically and will return you to the previous page.
I have a page which contains a WebView, when you use the directional buttons to place the focus box around that control, the B button no longer responds. You can use the A button to take control of the WebView and display the pointer and the B button then will return focus back as above but I cannot navigate back using the B button until you move the focus box to a different control. This also happens using AdControl since this uses WebView.
I have tried to capture KeyDown:
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
private void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
Debug.WriteLine(args.VirtualKey.ToString());
}
This responds with GamePadB, GamePadX etc but not when the focus box is around the WebView.
Is there anyway I can find out when the GamePad buttons (specifically B) are pressed when the focus box is around the WebView (or AdControl) and the control isn't engaged so I can manually invoke the backstack navigation?
Since this issue happens when using the XY focus mode for the app, if your OS version is 14393 or higher, one workaround for this issue is to use the mouse mode for this page which contains the webview by setting RequiresPointer="WhenFocused" as following:
<Page RequiresPointer="WhenFocused">
...
</Page>
And set another page to XY focus mode by using the following code in the app.xaml.cs:
this.RequiresPointerMode =
Windows.UI.Xaml.ApplicationRequiresPointerMode.WhenRequested;
For more information, please try to refer to the following article:
https://msdn.microsoft.com/en-us/windows/uwp/input-and-devices/designing-for-tv#mouse-mode

Navigation caching only when navigating back

I have a little bit of experience programming Android apps.
And now i am wondering if the same thing is possible:
(Android:)
When navigating in an android app between activities, the state of the previous activity is hold. By pressing the back button, you get the previous activity the way you left it. When navigating towards an activity, this opens the activity in the default state.
(UWP:)
Navigating between pages:
I have a page which should be cached for when i navigate back.
But when I navigate towards the page, it should open the page in the initial state.
How is this possible?
(I already am able to enable navigationcachemode. I wonder if i can disable it, or create a new instance of the page for example.)
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back)
NavigationCacheMode = NavigationCacheMode.Disabled;
base.OnNavigatedFrom(e);
}
Just disable the NavigationMode when you're navigating back from a page. So you force the creation of a new page when you'll navigate again to that page (and the NavigationMode will be set to the NavigationMode you set in the constructor or XAML).

Handling back navigation in WebBrowser control preserving the previous scroll position

I know there a lot of questions asking about how to handle the back navigation in the WebBrowser control in WP7. And a lot of answers too, to achieve the same, using stacks, InvokeScript, etc.., and I am currently using this approach, and it works fine (JavaScript):
private void BackButton_Click(object sender, EventArgs e)
{
try
{
webBrowser.InvokeScript("eval", "history.go(-1)");
}
catch (Exception)
{
}
}
But however say when a user scrolls down to section 'n' in a webpage, and a link from there takes him to a new page, and then the back button is pressed, the page successfully navigates back to the previous page, but is at the top of the page, i.e., section '1'.
I would however like to preserve the user's scroll position in the previous page, and send him back to the previous page and down at the position from where the link took him, so that he doesn't have to scroll down all over again, i.e., if a link at section 'n' takes him to page2 from page1, after clicking back, it should take him back to page1 and scrolled down till section 'n'.
Thanks.
(The back button that I'm using is a button on the ApplicationBar and not that of the phone's.)
Note: This is how the back button works in the Internet Explorer browser of the Windows Phone, preserving scroll positions.

Categories

Resources