Background page loading in a frame in universal windows app - c#

I have a SplitView control in my UWP app and when a particular ListBoxItem in the SplitView pane is Tapped a frame in the Main Page should navigate to that page. I have written the following code for that
private void Page2_Tapped(object sender, TappedRoutedEventArgs e)
{
PageLoadingProgress.IsActive = true;
MainApplicationSplitView.IsPaneOpen = false;
MainApplicationFrame.Navigate(typeof(Page2));
PageLoadingProgress.IsActive = false;
}
The issue I am facing is, whenever a ListBoxItem is tapped the whole app becomes unresponsive until Page2 is Loaded. The PageLoadingProgress ProgressRing cannot be seen and the SplitView pane doesn't close immediately as I expected. How to make this work? I want the pane to be closed and ProgressRing displayed when the page is loading and the app should be responsive.
Thanks in advance.

You are doing the work on UI thread, it blocks the UI and causes the lag you experienced.
This link should help you http://wpdev.apps-1and1.net/dispatcher-yield-when-and-how-to-use-it-on-winrt/

Related

UWP Tablet Mode back button not working

I have UWP app that implements the below code to wire up the system back button. My understanding is that this event is provided to capture hardware back buttons on Windows Phones, the back button in the title bar on Windows 10 and the back button on the task bar in Windows 10 tablet mode.
The hardware and title bar back buttons are working in my app, but when in tablet mode, pressing the back button on the task bar moves my app to the background and navigates to the Start Menu regardless of where I am in the app backstack. The BackRequested event IS firing in this case and my app is navigating back one page.
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested +=
App_BackRequested;
}
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
NavService.GoBack();
}
Any thoughts on why the tablet mode back button would behave this way? I'm seeing this behavior across many Windows 10 PCs, Surfaces, etc.
The default behavior of the Tablet mode back button is indeed to navigate out of the app. To prevent this you have to make sure that when you can navigate back in the app, you also mark the back navigation as handled.
private void App_BackRequested(object sender, BackRequestedEventArgs e)
{
if ( NavService.CanGoBack() )
{
NavService.GoBack();
e.Handled = true;
}
}
You will have to add a CanGoBack() method that will check the app Frame's CanGoBack property.

Back button controlling for my Windows Phone 8.1 Silverlight App

I am developing a Windows Phone 8.1 Silverlight app. In my app, I need to override the back button code.
So I tried this,
protected override void OnBackKeyPress(CancelEventArgs e)
{
//Navigating to this page when back button is pressed
DisplayPage mynewPage = new DisplayPage();
this.Content = mynewPage;
e.Cancel = true;
}
But this code is not working. What am I doing wrong? Please help me out.
EDIT:
When I place this code on MainPage, it works! But I don't want to place it there. I want to place it on other pages.
Remove "e.Cancel = true" (it cancels the navigation). Simply just navigate to the new page.
EDIT:
For navigating to another page, I would rather suggest using NavigationService. Check out this page for examples.
EDIT:
Code snippet:
protected override void OnBackKeyPress(CancelEventArgs e)
{
//Navigating to this page when back button is pressed
NavigationService.Navigate(new Uri("/DisplayPage.xaml", UriKind.Relative));
}

Accessing applicataion bar from non UI class windows phone 8

In my windows phone app I've a non-UI class which will show and hide a pop up screen when called from the UI page.
I want to hide the application bar when the pop up is shown and show the appbar again when the pop up is closed.
Now the challenge here is I've a timer in the non UI class which handles the closing of the pop up. So from the UI class I can only start the pop up. Closing is controlled by the non UI class. So now I need to access the appbar from the non UI class.
Can any one help me if I can do it or any work around if this cannot be done. ?
Thank you.
Maybe making use of Popup.Closed Event would help:
private void myPopup_Close(object sender, System.EventArgs e)
{
// get current Page
var currentPage = ((App.Current as App).RootVisual as PhoneApplicationFrame).Content as PhoneApplicationPage;
// hide popup
currentPage.ApplicationBar.IsVisible = true;
}

how to prevent going back to previous page

For a windows phone 8 app I'm developing, I had to load some data at the starting of the app. For that matter I designed a page called SplashScreen.xaml that loads the data and after all the loading is done I navigate to the MainPage.xaml using:
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
Now when the user is in the main page and taps the back button on the phone instead of going out of the app(which is the default gesture) goes back to the SplashScreen.xaml, making them unable to go out of the app(except for taping the start button which take's the app to background) and of course giving them a bad impression.
The question is How to prevent going back to the previous page
Thank you all.
Just clear the backstack when landing on MainPage:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
while (NavigationService.RemoveBackEntry() != null);
}

How to sync the Titlebar with SystemTray on Windows Phone 8?

I'm trying to replicate the behaviour that you can see on the new bing apps on Windows Phone 8. It shows the title of the app on top of the screen, when you tap that area the title slides offscreen and the status-icons slide-in.
I managed to get my titlebar up there and can slide the text off on a tap event.
Problem is I only get the tap event if SystemTray.IsVisible is set to false.
If I set the visibility to true inside my tap event it doesnt force the icons to show so it needs another tap to show the icons.
Does anyone know if I can catch the SystemTray Tap Event or if I can force the icons to show or maybe simulate a touch input?
It's way easier than you think. Just subscribe to the Loaded event of your page, and put a progress indicator in the system tray, displaying the text you want:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
var progressIndicator = new ProgressIndicator { Text = "Your title", IsVisible = true };
SystemTray.SetProgressIndicator(this, progressIndicator);
}
Note that you can also change the colors by using SystemTray.BackgroundColor and SystemTray.ForegroundColor

Categories