コード例 #1
0
        private void ToggleAwayModeEnabled(object _)
        {
            bool currentAwayModeEnabledSetting = IsAwayModeEnabled;

            bool desiredAwayModeEnabledSetting = !currentAwayModeEnabledSetting;

            //set value in current plan
            using (PowerPlan powerPlan = PowerPlan.GetActivePlan())
            {
                uint newSettingUint;
                if (desiredAwayModeEnabledSetting)
                {
                    newSettingUint = 1;
                }
                else
                {
                    newSettingUint = 0;
                }

                powerPlan.PowerWriteACValueIndex(PowerPlan.GUID_SLEEP_SUBGROUP, PowerPlan.AwayModeSetting, newSettingUint);
                powerPlan.ApplyCurrentValuesToSystem();
            }

            //read again from system
            UpdateAwayModeEnabledProperty();
            ApplyCurrentThreadExecutionState();
            CommandManager.InvalidateRequerySuggested();
        }
コード例 #2
0
        private void UpdateAwayModeEnabledProperty()
        {
            //check the current power configuration
            bool currentAwayModeEnabledSetting;

            using (PowerPlan powerPlan = PowerPlan.GetActivePlan())
            {
                object currentAwayModeEnabledSettingObject = powerPlan.PowerReadACValue(PowerPlan.GUID_SLEEP_SUBGROUP, PowerPlan.AwayModeSetting);
                currentAwayModeEnabledSetting = 1.Equals(currentAwayModeEnabledSettingObject);

                IsAwayModeEnabledProperty.SetValue(currentAwayModeEnabledSetting);
            }
        }