简体   繁体   English

修改绑定到控件属性的应用程序设置时,是否必须调用.Save()?

[英]Do you have to call .Save() when modifying a application setting that is bound to a control property?

I am programming in .NET I have an application setting of type string. 我在.NET中编程,我的应用程序设置为字符串类型。 On my form I have a textbox. 在我的表单上,我有一个文本框。 I bound the text property of the textbox to my application setting. 我将文本框的text属性绑定到我的应用程序设置。 If I type something in the textbox it changes the value that is held in the Application setting but the next time I start the program it goes back to the default value. 如果我在文本框中键入内容,它将更改“应用程序”设置中保留的值,但是下次我启动该程序时,它将恢复为默认值。 Do I need to call Properties.Settings.Default.Save(); 我是否需要调用Properties.Settings.Default.Save(); after the text is entered for the new value to be saved? 在输入文本后保存新值? Shouldn't it do this automatically? 它不应该自动执行此操作吗? Is there a way I can make it do it automatically? 有什么办法可以使其自动执行吗?

Yes, you need to call Save explicitly. 是的,您需要显式调用Save The binding changes the setting value in memory, but doesn't save the file 绑定会更改内存中的设置值,但不会保存文件

If you want it to be saved automatically, bind a handler to the TextChanged event and call Save() in it. 如果要自动保存它,请将处理程序绑定到TextChanged事件并在其中调用Save()。 It's just a double click and typing one line of code. 只需双击并输入一行代码即可。

It is common practice to call Properties.Settings.Default.Save(); 常见的做法是调用Properties.Settings.Default.Save(); when close the application (for example, in FormClosing event). 当关闭应用程序时(例如,在FormClosing事件中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置控件的属性时,可以在控件名称中使用字符串吗? - Can you use a string in the name of the control when setting its property? 将控件属性绑定到绑定到另一个属性的用户设置? - Binding a control property to a User Setting that is bound to another property? WPF-属性更改时绑定控件未更新? - WPF - Bound Control Not Updating When Property Changed? 我们是否具有WebBrowser控件,智能设备应用程序的ObjectForScripting属性? - Do we have ObjectForScripting property for WebBrowser Control, for Smart Device application? WPF用户控件依赖项属性绑定到ViewModel属性时不起作用 - WPF User Control Dependency Property not working when bound to a ViewModel property 当绑定数据更改时,用户控件上的依赖项属性不会更新属性 - Dependency Property on a user control not updating the property when bound data changes 使用使用范围时,是否必须调用Close方法? - When using the using scope, do you have to call Close methods? 没有异常对象时的Application Insights TrackException ExceptionTelemetry - Application Insights TrackException ExceptionTelemetry when you do not have an exception object 如何绑定到用户控件的属性? - How do you bind to the property of a User Control? 设置对象的DataSource属性时,何时使用类型与实例? - When setting the DataSource property of an object, when do you use a Type vs. an instance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM