using Windows.UI.Xaml;

namespace ViewSwitchingSample.Triggers
{
    /// <summary>
    /// The <see cref="DeviceFamilyTrigger"/> is a trigger, that gets activated when the given device family matches
    /// the current device family where the app is running on.
    /// </summary>
    public class DeviceFamilyTrigger : StateTriggerBase
    {
        private string targetDeviceFamily;

        public string DeviceFamily
        {
            get
            {
                return targetDeviceFamily;
            }

            set
            {
                targetDeviceFamily = value;
                var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
                if (qualifiers.ContainsKey("DeviceFamily"))
                {
                    var currentDeviceFamily = qualifiers["DeviceFamily"];
                    if (currentDeviceFamily == targetDeviceFamily)
                    {
                        SetActive(true);
                    }
                    else
                    {
                        SetActive(false);
                    }
                }
            }
        }
    }
}
