Skip to content

Instantly share code, notes, and snippets.

View colinkiama's full-sized avatar

Colin Kiama colinkiama

View GitHub Profile
@colinkiama
colinkiama / example1.cs
Created May 14, 2017 23:05
Example of targetting device specific code
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
//Do something with the Status Bar or specific to the phone.
}
@colinkiama
colinkiama / appContentInTitleBar.cs
Created May 14, 2017 23:20
Code that extends the window content into the title bar
//Inside OnLaunched method in App.Xaml.cs
var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Winodows.UI.ViewManagemnt.ApplicationViewTitleBar))
{
ApplicationViewTitleBar formattableTitleBar = appView.TitleBar;
formattableTitleBar.ButtonBackgroundColor = Colors.Transparent;
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
@colinkiama
colinkiama / specificDeviceFamily.cs
Created May 14, 2017 23:35
Actual device family specific code
var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "DeviceFamilyName")
{
//Any code you write here will only run in the device family you specified as the device family name.
}
@colinkiama
colinkiama / perfectDeviceSpecificCode.cs
Created May 14, 2017 23:45
finalDeviceSpecificCodeSolution
var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Desktop")
{
ApplicationViewTitleBar formattableTitleBar = appView.TitleBar;
formattableTitleBar.ButtonBackgroundColor = Colors.Transparent;
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
appView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
@colinkiama
colinkiama / DeviceTypeHelper.cs
Created December 11, 2017 04:17 — forked from wagonli/DeviceTypeHelper.cs
Detect device type on Universal Windows Platform (UWP)
using Windows.System.Profile;
using Windows.UI.ViewManagement;
namespace Wagonli.Tools
{
public static class DeviceTypeHelper
{
public static DeviceFormFactorType GetDeviceFormFactorType()
{
switch (AnalyticsInfo.VersionInfo.DeviceFamily)
@colinkiama
colinkiama / DeviceTypeHelper.cs
Created December 11, 2017 04:17 — forked from wagonli/DeviceTypeHelper.cs
Detect device type on Universal Windows Platform (UWP)
using Windows.System.Profile;
using Windows.UI.ViewManagement;
namespace Wagonli.Tools
{
public static class DeviceTypeHelper
{
public static DeviceFormFactorType GetDeviceFormFactorType()
{
switch (AnalyticsInfo.VersionInfo.DeviceFamily)
@colinkiama
colinkiama / DeviceTypeHelper.cs
Created December 11, 2017 04:17 — forked from wagonli/DeviceTypeHelper.cs
Detect device type on Universal Windows Platform (UWP)
using Windows.System.Profile;
using Windows.UI.ViewManagement;
namespace Wagonli.Tools
{
public static class DeviceTypeHelper
{
public static DeviceFormFactorType GetDeviceFormFactorType()
{
switch (AnalyticsInfo.VersionInfo.DeviceFamily)
@colinkiama
colinkiama / detect_orientation.cs
Created January 21, 2018 23:53 — forked from naotaco/detect_orientation.cs
Detect current screen orientation on UWP application.
private void Page_Loaded(object sender, RoutedEventArgs e)
{
DisplayInformation.GetForCurrentView().OrientationChanged += MainPage_OrientationChanged;
}
private void MainPage_OrientationChanged(DisplayInformation info, object args)
{
Debug.WriteLine("orientation: " + info.CurrentOrientation);
}
@colinkiama
colinkiama / detect_orientation.cs
Created January 21, 2018 23:53 — forked from naotaco/detect_orientation.cs
Detect current screen orientation on UWP application.
private void Page_Loaded(object sender, RoutedEventArgs e)
{
DisplayInformation.GetForCurrentView().OrientationChanged += MainPage_OrientationChanged;
}
private void MainPage_OrientationChanged(DisplayInformation info, object args)
{
Debug.WriteLine("orientation: " + info.CurrentOrientation);
}
@colinkiama
colinkiama / UWPCommunityToolkitContinuousRotations.cs
Last active February 27, 2018 15:27
Use Community Toolkit to animate a FontIcon continuously. Speed can be adjusted.
private async Task animateSyncingIcon()
{
nowSyncing = true;
var centerX = (float)syncIcon.ActualWidth / 2;
var centerY = (float)syncIcon.ActualHeight / 2;
const int maxRotation = 360;
double rotationsToPerform = 10;
double rotationsPerSecond = (double)(1 / rotationsToPerform);
var duration = (float)(rotationsPerSecond / maxRotation);
int rotation = 1;