我正在尝试将一系列布尔值保存在 settings.cs 文件中。这是我目前的保存方法。
private void SaveConfiguration()
{
VisibilitySwitchesFlags VisibilitySwitchesSaves = 0;
if (_menu.TreeItemDictionary[VisibilityItems.ReferenceLines].Checked)
VisibilitySwitchesSaves = VisibilitySwitchesFlags.ReferenceLinesChecked;
if (_menu.TreeItemDictionary[VisibilityItems.ShowProfilePoints].Checked)
VisibilitySwitchesSaves = VisibilitySwitchesFlags.ShowProfilePointsChecked;
Settings.Default.VisibilityViewStates = (int)VisibilitySwitchesSaves;//convert to int
Settings.Default.Save();
}
这是我的加载方法:
private void LoadConfiguration()
{
VisibilitySwitchesFlags flags =(VisibilitySwitchesFlags)Settings.Default.VisibilityViewStates;
_menu.TreeItemDictionary[VisibilityItems.ReferenceLines].Checked = flags.HasFlag(VisibilitySwitchesFlags.ReferenceLinesChecked);
_menu.TreeItemDictionary[VisibilityItems.ShowProfilePoints].Checked = flags.HasFlag(VisibilitySwitchesFlags.ShowProfilePointsChecked);
}
加载后,我的保存似乎不成功。我的方法有错误吗?