Skip to content

Instantly share code, notes, and snippets.

@konradbartecki
Last active October 27, 2015 09:49
Show Gist options
  • Save konradbartecki/8456910488a380da8036 to your computer and use it in GitHub Desktop.
Save konradbartecki/8456910488a380da8036 to your computer and use it in GitHub Desktop.
Windows Phone 8.1 Helpers
public static class InputScopeHelper
{
public static InputScope GetSingleScope(InputScopeNameValue myscope)
{
InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();
name.NameValue = myscope;
scope.Names.Add(name);
return scope;
}
}
using System.Globalization;
using Windows.ApplicationModel.Resources.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace WindowsPhoneHelpers
{
public static class LanguageSwitchHelper
{
public static void ChangeLanguage(string code, FlowDirection flowDirection)
{
var culture = new CultureInfo(code);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
var frame = Window.Current.Content as Frame;
if (frame != null)
frame.FlowDirection = flowDirection;
var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
ResourceManager.Current.DefaultContext.Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
}
}
}
using System;
namespace WindowsPhoneHelpers
{
public static class LocalSettingsHelper
{
public static bool? GetBool(string key)
{
try
{
bool b = (bool) Windows.Storage.ApplicationData.Current.LocalSettings.Values[key];
return b;
}
catch (NullReferenceException)
{
return null;
}
}
public static void SaveBool(string key, bool value)
{
Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
}
public static string GetString(string key)
{
try
{
string s = Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] as string;
return s;
}
catch (NullReferenceException)
{
return null;
}
}
public static void SaveString(string key, string value)
{
Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
}
}
}
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace WindowsPhoneHelpers
{
public static class NavigationHelper
{
public static void NavigateTo(Type pageType)
{
Frame rootFrame = Window.Current.Content as Frame;
if(rootFrame == null) return;
var currentPage = rootFrame.CurrentSourcePageType;
if (currentPage == pageType) return;
rootFrame.Navigate(pageType);
}
}
}
using Windows.UI.ViewManagement;
namespace WindowsPhoneHelpers
{
public static class ProgressIndicatorHelper
{
public static void ShowLoader(string loaderMessage)
{
StatusBarProgressIndicator progressbar = StatusBar.GetForCurrentView().ProgressIndicator;
progressbar.Text = loaderMessage;
progressbar.ShowAsync();
}
public static void HideLoader()
{
StatusBarProgressIndicator progressbar = StatusBar.GetForCurrentView().ProgressIndicator;
progressbar.HideAsync();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment