这是我的一些设置代码
if (settings.Contains("dynamicOn"))
{
// Commenting out because we're trying a different way
// DynamicCheck.IsChecked = (bool)settings["dynamicOn"];
dynamicToggle.IsChecked = (bool)settings["dynamicOn"];
AllPacks.IsChecked = (bool)settings["changeAllPacks"];
}
这是它背后的 XAML
<toolkit:ToggleSwitch x:Name="dynamicToggle" Header="Dynamically Update Lockscreen?" Margin="0,112,0,-112" SwitchForeground="White" Checked="DynamicCheck_Checked_1" Unchecked="DynamicCheck_Unchecked">
<toolkit:ToggleSwitch.HeaderTemplate>
<DataTemplate>
<ContentControl Content="{Binding}"/>
</DataTemplate>
</toolkit:ToggleSwitch.HeaderTemplate>
</toolkit:ToggleSwitch>
<CheckBox x:Name="AllPacks" Content="All Packs" Checked="AllPacks_Checked" Unchecked="AllPacks_Unchecked" Margin="50,174,0,0" Visibility="Collapsed"/>
现在,XAML 和 ToggleSwitch 都可以正常工作。所有这些都有效。只是,当我尝试实际打开我的设置页面时(没有 CheckBox 的东西打开就好了,但拒绝用它打开),我收到了这个错误
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.ni.dll The program '[3048] TaskHost.exe' has exited with code -1 (0xffffffff).
有没有人见过这个?搜索 Bing 似乎对我没有任何帮助。任何帮助将不胜感激!
谢谢,帕特里克
编辑:我已将代码更改为此
if (settings.Contains("dynamicOn"))
{
// Commenting out because we're trying a different way
// DynamicCheck.IsChecked = (bool)settings["dynamicOn"];
AllPacks.IsChecked = (bool)settings["changeAllPacks"];
dynamicToggle.IsChecked = (bool)settings["dynamicOn"];
}
else
{
// Commenting out because we're trying a different way
// DynamicCheck.IsChecked = true;
// isEnabledText.Visibility = Visibility.Visible;
// settings.Add("dynamicOn", true);
dynamicToggle.IsChecked = true;
AllPacks.IsChecked = true;
AllPacks.Visibility = Visibility.Visible;
settings.Add("changeAllPacks", true);
settings.Add("dynamicOn", true);
}
现在它在
settings.Add("dynamicOn", true);
并且错误也更改为
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.ni.dll
所以,我开始认为这可能是一个独立存储问题?