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

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

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.

How to set WPF app to always be inactive so it does not steal focus from other apps

What I want:
Set my WPF to inactive all the time, even when I press buttons, whatever I do with that WPF app as I'm interacting with it, I don't want any other app to lose it's focus/activation, for example, how does a software keyboard work? if the keyboard is to input text correctly, the active window (google for example) has to remain active while the software keyboard is being used, otherwise the keyboard would not be able to input keystrokes since google lost focus/activation when the keyboard is touched.
What I want to do:
private void button_Click(object sender, RoutedEventArgs e)
{
InputSimulator.SimulateTextEntry("1");
}
My WPF needs to send that keystroke text into the active window of 'google' for example, but when I press the button the focus/activation from google is lost and it is now in my WPF app, due to this I could not send the keystroke, just imagine the surface pro 3 software keyboard, when you press it's buttons it does not take away the current applications focus/activation, I want to do something similar, how do I do it?
Not sure if it possible because you just focus a window on click.
You could unfocus the mainwindow all the time when it got focused.
public partial class App : Application
{
public App()
{
Activated += (s,e) =>
{
App.Current.MainWindow.SetValue(MyApp.MainWindow.IsFocusedProperty, false);
};
}
}

Background page loading in a frame in universal windows app

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/

how to get height of keyboard suggestion bar windows phone 8?

Currently I am working on windows phone 8.
When a textbox get focus in popup window it hide under the keyboard. I've tried subtracting the keyboard height from the VerticalOffset of popup window. But still the textbox is hiding under the keyboard because of the suggestion bar of the keyboard. Is there any way to get the height of keyboard's suggestion bar?
Thanks!!!
Not in a Windows Phone 8 Silverlight app
If you upgrade to a Windows Phone 8.1 Silverlight app (or Runtime, but that's a bigger update) then you can use the InputPane class and examine its OccludedRect property in the Showing event.
This will fire whenever the keyboard changes what it covers, so you'll get the event once when the keyboard first opens and then again when the suggestion bar slides up.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing += MainPage_Showing;
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Hiding += MainPage_Hiding;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Showing -= MainPage_Showing;
Windows.UI.ViewManagement.InputPane.GetForCurrentView().Hiding -= MainPage_Hiding;
}
void MainPage_Hiding(Windows.UI.ViewManagement.InputPane sender, Windows.UI.ViewManagement.InputPaneVisibilityEventArgs args)
{
Debug.WriteLine("Hiding and occluding {0}", sender.OccludedRect.Height);
}
void MainPage_Showing(Windows.UI.ViewManagement.InputPane sender, Windows.UI.ViewManagement.InputPaneVisibilityEventArgs args)
{
Debug.WriteLine("Showing and occluding {0}", sender.OccludedRect.Height);
}
Depending on your layout this may not be necessary on WP8.1. I tested a WP8 app on the WP8.1 emulator and the TextBoxes in my Popup slid out of the way of the suggestion bar as well as out of the way of the keyboard. If your layout is complex enough that doesn't work (e.g. if you need to move things below the focused TextBox as well) then you can handle Showing to move things yourself and then set InputPaneVisibilityEventArgs.EnsuredFocusedElementInView to let the InputPane not to also move things itself.

WP8.1 AppBar size change

How do I monitor AppBar's size changes? Specifically, I want to know when it gets opened(to show secondary commands and labels underneath icons).
There is a SizeChanged event, but it fires only before AppBar is shown on the screen.
CommandBar has Opened and Closed events. They are fired when SecondayCommands are shown/hidden.
Note that those events will be fired only if you have SecondayCommands in your AppBar.
As I've checked - Opening/Closing your AppBar doesn't change its ActualHeight. If you want to see its size changing you can play with ClosedDisplayMode - for example put this code in your AppBarButton.Click:
private void AppBarToggleButton_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine(BottomAppBar.ActualHeight.ToString());
if (BottomAppBar.ClosedDisplayMode == AppBarClosedDisplayMode.Compact)
BottomAppBar.ClosedDisplayMode = AppBarClosedDisplayMode.Minimal;
else BottomAppBar.ClosedDisplayMode = AppBarClosedDisplayMode.Compact;
}
The code above changes ActualHeight and thus SizeChanged event is being fired.

Categories