Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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