Last active
March 3, 2016 22:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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