Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a TextBox hold text when app is shut down and restarted using user settings
    primarykey
    data
    text
    <p>Before I begin with my question I've been reading every link imaginable on the subject and I'm still stuck.</p> <p>I am putting together a WPF using C# and Visual Studio. I want to have a TextBox retain text in it when the application to shut down and restarted and that the text is read/write because the text will change often.</p> <p>I've set up a new .settings file and have it in my Properties folder in my project. I created this using the nifty grid where I can make a name, type, and value etc etc.</p> <p>So far after several several hours I think I'm closer yet am not sure. This is the Designer.cs - </p> <pre><code>namespace PRX.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] internal sealed partial class saveData : global::System.Configuration.ApplicationSettingsBase { private static saveData defaultInstance = ((saveData)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new saveData()))); public static saveData Default { get { return defaultInstance; } } [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("mainSource")] public string Setting { get { return ((string)(this["Setting"])); } set { this["Setting"] = value; } } } } </code></pre> <p>The .settings file is called saveData.settings and I have the table set up as Name: Setting , Type: String, Value: mainSource. The Scope is set to user. This is in the Properties folder just like the default Settings.settings files.</p> <p>The TextBox in questions has this connected like so:</p> <pre><code> &lt;ScrollViewer VerticalScrollBarVisibility="Auto"&gt; &lt;TextBox DockPanel.Dock="Top" Margin="10" Background="Black" Name="tb1" TextWrapping="Wrap" AcceptsReturn="True" Text="{Binding Source={x:Static p:saveData.Default}, Path=Default.Setting, Mode=TwoWay}"&gt;&lt;/TextBox&gt; &lt;/ScrollViewer&gt; </code></pre> <p>And for good measure here's how it looks like in the app.config:</p> <pre><code> &lt;PRX.saveData&gt; &lt;setting name="Setting" serializeAs="String"&gt; &lt;value&gt;mainSource&lt;/value&gt; &lt;/setting&gt; &lt;/PRX.saveData&gt; &lt;/userSettings&gt; </code></pre> <p>I know it's connected to the .Settings file because when I debug the value 'mainSource' is present in the Textbox</p> <p>I've read over dozen links on the subject but most notably these two:</p> <p><a href="http://blogs.msdn.com/b/patrickdanino/archive/2008/07/23/user-settings-in-wpf.aspx" rel="nofollow">http://blogs.msdn.com/b/patrickdanino/archive/2008/07/23/user-settings-in-wpf.aspx</a> <a href="http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx</a></p> <p>I am especially confused with this, the documentation I am reading seems very straight-forward yet I can't seem to grasp it. Any help is supremely appreciated. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload