獲取當前裝置系列

這裡有一個簡單的便攜方式來獲取當前的裝置系列:

/// <summary>
/// All the device families 
/// </summary>
public enum DeviceFamily
{
    Desktop,
    Mobile,
    Iot,
    Xbox,
}

/// <summary>
/// The helper to get the current device family
/// </summary>
public static class DeviceFamilyHelper
{
    /// <summary>
    /// Return the family of the current device
    /// </summary>
    /// <returns>the family of the current device</returns>
    public static DeviceFamily GetDeviceFamily()
    {
        switch(ResourceContext.GetForCurrentView().QualifierValues["DeviceFamily"].ToLowerInvariant())
        {
            case "mobile":  return DeviceFamily.Mobile;    
            case "xbox":    return DeviceFamily.Xbox;
            case "iot":     return DeviceFamily.Iot;
            default:        return DeviceFamily.Desktop;
        }
    }
}