如何保存用户估算值在文本框? (WPF,XAML) [英] How to save user imputed value in TextBox? (WPF, XAML)

查看:150
本文介绍了如何保存用户估算值在文本框? (WPF,XAML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存在文本框的用户估算值? (WPF XAML)所以在我的XAML的窗口我有一个文本框。用户sturts我的应用程序输入一些数值到它和presses按钮或提示输入。他关闭的应用程序。再次打开它。如何使自己的输入保存在文本框在WPF?

How to save user imputed value in TextBox? (WPF XAML) So in my xaml window I have a TextBox. User sturts my application inputs some values in to it and presses a button or hints Enter. He closes an app. Opens it up again. How to make his inputs be saved in that TextBox in WPF?

推荐答案

您可以使用内置的.NET设置。

You can use the built in .net settings.

在Visual Studio中,右键点击你的项目,然后选择添加新项。在对话框中,选择设置文件,并给它一个名称,如MySettings。 Visual Studio将创建一些文件,包括 MySettings 类的一些静态方法来提供您访问的设置。

In visual studio, right click on your project and choose Add new item. From the dialog, select "Settings file", and give it a name like "MySettings". Visual studio will create a few files including a MySettings class with some static methods to provide you access to your settings.

如果你打开​​这个文件,你会得到一个不错的网格的用户界面,使您可以输入一些设置,设置它们的类型(在这种情况下,字符串),并设置一个默认值。它也允许你指定,如果他们的应用程序或用户的设置。

If you open this file up, you will be given a nice grid ui that allows you to enter some settings, set their type (in this case String) and set a default value. It also allows you to specify if they are application or user settings.

  • 应用程序设置:无法在应用程序启动后修改。只能通过编辑XML config文件进行configued。会不会是相同的谁运行的应用程序,每一位用户。
  • 用户设置:可以修改,应用程序运行时保存。将存储在用户的的Documents and Settings \用户名\本地设置文件夹。可以为每个用户不同。
  • Application settings: Cannot be modified after the app has started. Can only be configued by editing an xml .config file. Will be the same for every user who runs the app.
  • User settings: Can be modified and saved while the application is running. Will be stored in the users documents and settings\username\local settings folder. Can be different for every user.

有关你所描述的,选择用户的范围。

For what you are describing, choose "User" for the scope.

现在,进入价值code:

Now, to access the value in code:

// Load the value into the text box.
txtBox1.text = MySettings.Default.SomeSetting;

和保存的改变:

// Update the value.
MySettings.Default.SomeSetting = txtBox1.text;

// Save the config file.
MySettings.Default.Save();

有一个关于所有这一切都在这里 MSDN 更多的信息,还有的更多信息在<一个href="http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.aspx">ApplicationSettingsBase一流这里

<子>(显然,如果您使用的是MVV​​M,或任何其他UI模式,你能适应这种code加载设置值代入模型/的ViewModels适当的时机,而不是直接在文本框中)

这篇关于如何保存用户估算值在文本框? (WPF,XAML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆