Skip to content

Instantly share code, notes, and snippets.

@Delaire
Last active January 26, 2016 16:56
Show Gist options
  • Save Delaire/e2431a510783393f8c39 to your computer and use it in GitHub Desktop.
Save Delaire/e2431a510783393f8c39 to your computer and use it in GitHub Desktop.
A StatusBarHelper on a Windows Universal application for Mobile, using Windows Mobile Extensions for the UWP reference
public static class StatusBarHelper
{
private static StatusBar statusBar
{
get
{
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
return StatusBar.GetForCurrentView();
}
return null;
}
}
public static async Task Hide()
{
if (statusBar!=null)
{
await statusBar.HideAsync();
}
}
public static async Task Show()
{
if (statusBar != null)
{
await statusBar.ShowAsync();
}
}
public static async Task SetAppStatusBar()
{
if (statusBar != null)
{
//statusBar.BackgroundColor = Color.FromArgb(0, 0, 171, 169);
statusBar.BackgroundColor = Color.FromArgb(0, 0, 109, 11);
statusBar.BackgroundOpacity = 1;
statusBar.ForegroundColor = Colors.White;
}
}
public static async Task SetAppStatusBarError()
{
if (statusBar != null)
{
//statusBar.BackgroundColor = Color.FromArgb(0, 0, 171, 169);
statusBar.BackgroundColor = Colors.Red;
statusBar.BackgroundOpacity = 1;
statusBar.ForegroundColor = Colors.White;
}
}
public static async Task ShowLoading(string text)
{
if (statusBar != null)
{
await SetAppStatusBar();
Show();
statusBar.ProgressIndicator.Text = text;
await statusBar.ProgressIndicator.ShowAsync();
}
}
public static async Task ShowErrorLoading(string text)
{
if (statusBar != null)
{
await SetAppStatusBarError();
Show();
statusBar.ProgressIndicator.Text = text;
await statusBar.ProgressIndicator.ShowAsync();
}
}
public static async Task HideLoading()
{
if (statusBar != null)
{
await statusBar.ProgressIndicator.HideAsync();
statusBar.ProgressIndicator.Text = string.Empty;
}
}
public static async Task HideLoadingDelay(int mdelay)
{
if (statusBar != null)
{
await Task.Delay(mdelay);
await HideLoading();
Hide();
}
}
public static async Task HideLoadingWithFinalText(string s, int mdelay)
{
if (statusBar != null)
{
await ShowLoading(s);
await Task.Delay(mdelay);
await HideLoading();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment