我正在尝试创建一个ComboBox并使用设置文件填充值。 在第一次尝试时它可以工作但是当我尝试更改设置文件中的值时,它不会反映在ComboBox中的项目列表中。 代码片段相同 -
ComboBox xaml代码 -
<ComboBox Name="vGameMode"
ItemsSource="{Binding Source={x:Static p:Settings1.Default}, Path=Modes}"
SelectedIndex="1">
<!-- <ComboBoxItem Content="Personal"/>
<ComboBoxItem Content="Corporate"/> -->
</ComboBox>
设置文件中的值 -
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ABC" GeneratedClassName="Settings1">
<Profiles />
<Settings>
<Setting Name="Themes" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>Theme1</string>
<string>Theme2</string>
<string>Theme3</string>
</ArrayOfString></Value>
</Setting>
<Setting Name="DefaultMaxScore" Type="System.Int32" Scope="User">
<Value Profile="(Default)">1000</Value>
</Setting>
<Setting Name="DefaultTimeoutSeconds" Type="System.Int32" Scope="User">
<Value Profile="(Default)">300</Value>
</Setting>
<Setting Name="LeaderboardDays" Type="System.Int32" Scope="User">
<Value Profile="(Default)">7</Value>
</Setting>
<Setting Name="NumberOfTasks" Type="System.Int32" Scope="User">
<Value Profile="(Default)">3</Value>
</Setting>
<Setting Name="CurrentModeIndex" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="DifficultyLevels" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>Medium</string>
<string>Hard</string>
</ArrayOfString></Value>
</Setting>
<Setting Name="GameType" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)"><?xml version="1.0" encoding="utf-16"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>Laser Maze</string>
<string>Laser Buster</string>
</ArrayOfString></Value>
</Setting>
</Settings>
</SettingsFile>
知道这里有什么问题吗? 我猜它是在某处缓存但不确定在哪里。
答案 0 :(得分:0)
确保在那里的某处调用Settings1.Default.Save()。我一直忘记这一点。