Skip to content

Instantly share code, notes, and snippets.

@Delaire
Last active March 3, 2016 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Delaire/a984bca44c47cfaa9766 to your computer and use it in GitHub Desktop.
Save Delaire/a984bca44c47cfaa9766 to your computer and use it in GitHub Desktop.
This file is to be used with this gist: https://gist.github.com/Delaire/37cbe07738df34bfd5e8 you will be able to use an adaptive trigger depending on the device type, this code is base on @dotMorten code which can be found here: https://github.com/dotMorten/WindowsStateTriggers/blob/master/src/WindowsStateTriggers/DeviceFamilyStateTrigger.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace Win10.StateTriggers
{
//you will also need https://gist.github.com/Delaire/37cbe07738df34bfd5e8
public class DeviceFamilyStateTrigger : StateTriggerBase
{
private static DeviceTypeEnum deviceFamily;
static DeviceFamilyStateTrigger()
{
deviceFamily = DeviceTypeHelper.GetDeviceType();
}
public DeviceTypeEnum DeviceFamily
{
get { return (DeviceTypeEnum)GetValue(DeviceFamilyProperty); }
set { SetValue(DeviceFamilyProperty, value); }
}
public static readonly DependencyProperty DeviceFamilyProperty =
DependencyProperty.Register("DeviceFamily", typeof(DeviceTypeEnum), typeof(DeviceFamilyStateTrigger),
new PropertyMetadata(DeviceTypeEnum.Other, OnDeviceTypePropertyChanged));
private static void OnDeviceTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var obj = (DeviceFamilyStateTrigger)d;
var val = (DeviceTypeEnum)e.NewValue;
if (deviceFamily == val)
obj.IsActive = true;
}
private bool m_IsActive;
public bool IsActive
{
get { return m_IsActive; }
private set
{
if (m_IsActive != value)
{
m_IsActive = value;
base.SetActive(value);
if (IsActiveChanged != null)
IsActiveChanged(this, EventArgs.Empty);
}
}
}
public event EventHandler IsActiveChanged;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment