C# ViewModel中的Properties.Settings.Default.Save()是否可行?
很奇怪,但我无法让它在ViewModel中运行C# ViewModel中的Properties.Settings.Default.Save()是否可行?,c#,wpf,viewmodel,C#,Wpf,Viewmodel,很奇怪,但我无法让它在ViewModel中运行 public class SmallWindow_ViewModel { public string My_property { get { return _my_property; } set { Set(ref _my_property, value); } } private string _my_property; public void S
public class SmallWindow_ViewModel
{
public string My_property
{
get { return _my_property; }
set { Set(ref _my_property, value); }
}
private string _my_property;
public void SmallWindow_unloaded()
{
Properties.Settings.Default.My_property_setting = My_property;
Properties.Settings.Default.Save();
}
}
如果将它放在代码中,它就会工作。谁调用
SmallWindow\u unload
?您好,方法工作,我已经检查过了。指挥部。ViewModel本身正在工作。当属性值放置在ViewModel中时,我无法保存属性值。同样的代码在CB中工作得很好。肯定还有更多。假设ViewModel与视图位于同一程序集中,属性
没有理由在代码隐藏中工作,而不是在ViewModel方法中工作。那应该很好。我尝试了一个非常简单的例子来确保它对我来说运行良好。你能展示一下你的代码是如何使用的吗?您确定My_属性
包含值吗?这个方法真的被调用了吗?你怎么知道它不起作用?