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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
You can use the built in .net settings.
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.documents and settings\username\local settings
folder. Can be different for every user.For what you are describing, choose "User" for the scope.
Now, to access the value in code:
and to save a change:
There's more information about all of this on MSDN here, and there is more information on the ApplicationSettingsBase class here.
(Obviously, if you are using mvvm, or any other UI pattern you can adapt this code to load the settings values into your model/viewmodels whenever it's appropriate rather than directly into the text box)