这里有两个问题
1、wpf程序中 app.xaml是干什么用的?除了配置些全局的样式以外,能和C#中的app.config一样用吗?
2、我在WPF程序中 添加了app.config的配置文件,想保存些信息,可是修改不了,不知道是什么原因,刚接触WPF,求解
app.config代码如下:<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="index" value="1"/>
</appSettings>
</configuration>后台Loaded中读取代码://读取配置文件
try
{
imgIndex = int.Parse(ConfigurationManager.AppSettings["index"]); }
catch (Exception)
{ imgIndex = 0;
}修改保存配置文件://修改配置文件
private void UpdateConfig(string newKey,string newValue)
{
bool isHasNode = false;
foreach (string key in ConfigurationManager.AppSettings)
{
if (key==newKey)
{
isHasNode = true;
}
}
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (isHasNode)
{
config.AppSettings.Settings.Remove(newKey);
}
config.AppSettings.Settings.Add(newKey,newValue);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings"); }读取没问题 ,修改不了,不知道为什么,求解!~
1、wpf程序中 app.xaml是干什么用的?除了配置些全局的样式以外,能和C#中的app.config一样用吗?
2、我在WPF程序中 添加了app.config的配置文件,想保存些信息,可是修改不了,不知道是什么原因,刚接触WPF,求解
app.config代码如下:<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="index" value="1"/>
</appSettings>
</configuration>后台Loaded中读取代码://读取配置文件
try
{
imgIndex = int.Parse(ConfigurationManager.AppSettings["index"]); }
catch (Exception)
{ imgIndex = 0;
}修改保存配置文件://修改配置文件
private void UpdateConfig(string newKey,string newValue)
{
bool isHasNode = false;
foreach (string key in ConfigurationManager.AppSettings)
{
if (key==newKey)
{
isHasNode = true;
}
}
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (isHasNode)
{
config.AppSettings.Settings.Remove(newKey);
}
config.AppSettings.Settings.Add(newKey,newValue);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings"); }读取没问题 ,修改不了,不知道为什么,求解!~
解决方案 »
- c# 如何生成不依赖于.net framework的应用程序
- 快速处理异常的问题
- 请问如何将DataGridViewTextBoxColumn和DataGridViewButtonColumn组合成一个新列,即带编辑按钮的列?
- C#建立了一个windows程序,如何防止多个程序实例运行?有什么技巧吗?
- DataGrid分页的特殊情况
- 【求助】VS2010 + DirectJun2010 + C# 运行出错
- #$##$我要注册国际域名的问题,专来来帮忙%#@$!$!@!@
- 如何在c#中调用帮助文件?
- 【C#菜鸟一个】请教各位大大、关于Visual Studio 2010 帮助问题
- 如何弹出另外增加的一个表单?
- 动态执行语句,求高手帮忙
- 如何判断DataGridView的单元格内容编辑完成?
是权限问题吗? 还是其他问题