diff --git a/dotnet-desktop-guide/framework/wpf/app-development/persist-and-restore-application-scope-properties.md b/dotnet-desktop-guide/framework/wpf/app-development/persist-and-restore-application-scope-properties.md index 8693aa36c1..ac993af3cb 100644 --- a/dotnet-desktop-guide/framework/wpf/app-development/persist-and-restore-application-scope-properties.md +++ b/dotnet-desktop-guide/framework/wpf/app-development/persist-and-restore-application-scope-properties.md @@ -1,7 +1,7 @@ --- title: "How to: Persist and Restore Application-Scope Properties Across Application Sessions" description: Learn how to persist and restore application-scope properties across application sessions via included code examples in XAML, C#, and Visual Basic. -ms.date: "03/30/2017" +ms.date: 06/13/2024 dev_langs: - "csharp" - "vb" @@ -18,11 +18,17 @@ ms.assetid: 55d5904a-f444-4eb5-abd3-6bc74dd14226 This example shows how to persist application-scope properties when an application shuts down, and how to restore application-scope properties when an application is next launched. -## Example +## Example - The application persists application-scope properties to, and restores them from, isolated storage. Isolated storage is a protected storage area that can safely be used by applications without file access permission. The *App.xaml* file defines the `App_Startup` method as the handler for the event, and the `App_Exit` method as the handler for the event, as shown in the highlighted lines of the first example. The second example shows a portion of the *App.xaml.cs* and *App.xaml.vb* files that highlights the code for the `App_Startup` method, which restores application-scope properties, and the `App_Exit` method, which saves application-scope properties. +The application persists application-scope properties to, and restores them from, isolated storage. Isolated storage is a protected storage area that can safely be used by applications without file access permission. The *App.xaml* file defines the `App_Startup` method as the handler for the event, and the `App_Exit` method as the handler for the event, as shown in the highlighted lines of the following XAML: - [!code-xaml[HOWTOApplicationModelSnippets#PersistRestoreAppScopePropertiesXAML1](~/samples/snippets/csharp/VS_Snippets_Wpf/HOWTOApplicationModelSnippets/CSharp/App.xaml?highlight=1-7)] - - [!code-csharp[HOWTOApplicationModelSnippets#PersistRestoreAppScopePropertiesCODEBEHIND1](~/samples/snippets/csharp/VS_Snippets_Wpf/HOWTOApplicationModelSnippets/CSharp/App.xaml.cs?highlight=17-55)] - [!code-vb[HOWTOApplicationModelSnippets#PersistRestoreAppScopePropertiesCODEBEHIND1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/HOWTOApplicationModelSnippets/visualbasic/application.xaml.vb?highlight=14-45)] +> [!NOTE] +> The following XAML is written for CSharp. The Visual Basic version omits the class declaration. + +:::code language="xaml" source="./snippets/persist-and-restore-application-scope-properties/csharp/App.xaml" highlight="5,6"::: + +This next example shows the Application code-behind, which contains the event handlers for the XAML. The `App_Startup` method restores application-scope properties, and the `App_Exit` method saves application-scope properties. + +:::code language="csharp" source="./snippets/persist-and-restore-application-scope-properties/csharp/App.xaml.cs"::: + +:::code language="vb" source="./snippets/persist-and-restore-application-scope-properties/vb/Application.xaml.vb"::: diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/App.xaml b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/App.xaml new file mode 100644 index 0000000000..d7d155ed9b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/App.xaml @@ -0,0 +1,7 @@ + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/App.xaml.cs b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/App.xaml.cs new file mode 100644 index 0000000000..1a877fc76f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/App.xaml.cs @@ -0,0 +1,66 @@ +using System.IO.IsolatedStorage; +using System.IO; +using System.Windows; + +namespace SDKSamples +{ + public partial class App : Application + { + string _filename = "App.data"; + + public App() + { + // Initialize application-scope property + Properties["NumberOfAppSessions"] = "0"; + } + + private void App_Startup(object sender, StartupEventArgs e) + { + // Restore application-scope property from isolated storage + IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForDomain(); + try + { + if (storage.FileExists(_filename)) + { + using (IsolatedStorageFileStream stream = storage.OpenFile(_filename, FileMode.Open, FileAccess.Read)) + using (StreamReader reader = new StreamReader(stream)) + { + // Restore each application-scope property individually + while (!reader.EndOfStream) + { + string[] keyValue = reader.ReadLine().Split(new char[] { ',' }); + Properties[keyValue[0]] = keyValue[1]; + } + } + } + } + catch (DirectoryNotFoundException ex) + { + // Path the file didn't exist + } + catch (IsolatedStorageException ex) + { + // Storage was removed or doesn't exist + // -or- + // If using .NET 6+ the inner exception contains the real cause + } + } + + private void App_Exit(object sender, ExitEventArgs e) + { + // Increase the amount of times the app was opened + Properties["NumberOfAppSessions"] = int.Parse((string)Properties["NumberOfAppSessions"]) + 1; + + // Persist application-scope property to isolated storage + IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForDomain(); + using (IsolatedStorageFileStream stream = storage.OpenFile(_filename, FileMode.Create, FileAccess.Write)) + using (StreamWriter writer = new StreamWriter(stream)) + { + // Persist each application-scope property individually + foreach (string key in Properties.Keys) + writer.WriteLine("{0},{1}", key, Properties[key]); + } + } + } + +} diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/AssemblyInfo.cs b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/AssemblyInfo.cs new file mode 100644 index 0000000000..cc29e7f741 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/MainWindow.xaml new file mode 100644 index 0000000000..b31dbd884b --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/MainWindow.xaml @@ -0,0 +1,14 @@ + + + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/MainWindow.xaml.cs b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/MainWindow.xaml.cs new file mode 100644 index 0000000000..0b0203e2e9 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/MainWindow.xaml.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace SDKSamples +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + lblTimes.Content = App.Current.Properties["NumberOfAppSessions"]; + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/ProjectCS.csproj b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/ProjectCS.csproj new file mode 100644 index 0000000000..0336b4ecc2 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/ProjectCS.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net481 + true + SDKSamples + app.manifest + + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/app.manifest b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/app.manifest new file mode 100644 index 0000000000..c522bb43f3 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/csharp/app.manifest @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/App.config b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/App.config new file mode 100644 index 0000000000..aee9adf485 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/Application.xaml b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/Application.xaml new file mode 100644 index 0000000000..fbdd38f974 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/Application.xaml @@ -0,0 +1,7 @@ + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/Application.xaml.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/Application.xaml.vb new file mode 100644 index 0000000000..071593cd42 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/Application.xaml.vb @@ -0,0 +1,61 @@ +Imports System.IO +Imports System.IO.IsolatedStorage + +Class Application + + Private _filename As String = "App.data" + + Public Sub New() + ' Initialize application-scope property + Properties("NumberOfAppSessions") = "0" + End Sub + + Private Sub App_Startup(ByVal sender As Object, ByVal e As StartupEventArgs) + ' Restore application-scope property from isolated storage + Dim storage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForDomain() + Try + If storage.FileExists(_filename) Then + + Using stream As IsolatedStorageFileStream = storage.OpenFile(_filename, FileMode.Open, FileAccess.Read) + Using reader As New StreamReader(stream) + + ' Restore each application-scope property individually + Do While Not reader.EndOfStream + Dim keyValue() As String = reader.ReadLine().Split(New Char() {","c}) + Properties(keyValue(0)) = keyValue(1) + Loop + + End Using + End Using + + End If + + Catch ex As DirectoryNotFoundException + ' Path the file didn't exist + Catch ex As IsolatedStorageException + ' Storage was removed or doesn't exist + ' -or- + ' If using .NET 6+ the inner exception contains the real cause + End Try + End Sub + + Private Sub App_Exit(ByVal sender As Object, ByVal e As ExitEventArgs) + 'Increase the amount of times the app was opened + Properties("NumberOfAppSessions") = Integer.Parse(DirectCast(Properties("NumberOfAppSessions"), String)) + 1 + + ' Persist application-scope property to isolated storage + Dim storage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForDomain() + + Using stream As IsolatedStorageFileStream = storage.OpenFile(_filename, FileMode.Create, FileAccess.Write) + Using writer As New StreamWriter(stream) + + ' Persist each application-scope property individually + For Each key As String In Properties.Keys + writer.WriteLine("{0},{1}", key, Properties(key)) + Next key + + End Using + End Using + End Sub + +End Class diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/AssemblyInfo.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/AssemblyInfo.vb new file mode 100644 index 0000000000..025ee7271e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/AssemblyInfo.vb @@ -0,0 +1,11 @@ +Imports System.Windows + +'The ThemeInfo attribute describes where any theme specific and generic resource dictionaries can be found. +'1st parameter: where theme specific resource dictionaries are located +'(used if a resource is not found in the page, +' or application resource dictionaries) + +'2nd parameter: where the generic resource dictionary is located +'(used if a resource is not found in the page, +'app, and any theme specific resource dictionaries) + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/MainWindow.xaml new file mode 100644 index 0000000000..d37697b764 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/MainWindow.xaml @@ -0,0 +1,14 @@ + + + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/MainWindow.xaml.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/MainWindow.xaml.vb new file mode 100644 index 0000000000..0f149c6098 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/MainWindow.xaml.vb @@ -0,0 +1,5 @@ +Public Class MainWindow + Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) + lblTimes.Content = Application.Current.Properties("NumberOfAppSessions") + End Sub +End Class diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/AssemblyInfo.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/AssemblyInfo.vb new file mode 100644 index 0000000000..0c518abf27 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/AssemblyInfo.vb @@ -0,0 +1,59 @@ +Imports System +Imports System.Globalization +Imports System.Reflection +Imports System.Resources +Imports System.Runtime.InteropServices +Imports System.Windows + +' General Information about an assembly is controlled through the following +' set of attributes. Change these attribute values to modify the information +' associated with an assembly. + +' Review the values of the assembly attributes + + + + + + + + + +'In order to begin building localizable applications, set +'CultureYouAreCodingWith in your .vbproj file +'inside a . For example, if you are using US english +'in your source files, set the to "en-US". Then uncomment the +'NeutralResourceLanguage attribute below. Update the "en-US" in the line +'below to match the UICulture setting in the project file. + +' + + +'The ThemeInfo attribute describes where any theme specific and generic resource dictionaries can be found. +'1st parameter: where theme specific resource dictionaries are located +'(used if a resource is not found in the page, +' or application resource dictionaries) + +'2nd parameter: where the generic resource dictionary is located +'(used if a resource is not found in the page, +'app, and any theme specific resource dictionaries) + + + + +'The following GUID is for the ID of the typelib if this project is exposed to COM + + +' Version information for an assembly consists of the following four values: +' +' Major Version +' Minor Version +' Build Number +' Revision +' +' You can specify all the values or you can default the Build and Revision Numbers +' by using the '*' as shown below: +' + + + diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/MyExtensions/MyWpfExtension.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/MyExtensions/MyWpfExtension.vb new file mode 100644 index 0000000000..22f84b7da5 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/MyExtensions/MyWpfExtension.vb @@ -0,0 +1,121 @@ +#If _MyType <> "Empty" Then + +Namespace My + ''' + ''' Module used to define the properties that are available in the My Namespace for WPF + ''' + ''' + _ + Module MyWpfExtension + Private s_Computer As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Devices.Computer) + Private s_User As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.ApplicationServices.User) + Private s_Windows As New ThreadSafeObjectProvider(Of MyWindows) + Private s_Log As New ThreadSafeObjectProvider(Of Global.Microsoft.VisualBasic.Logging.Log) + ''' + ''' Returns the application object for the running application + ''' + _ + Friend ReadOnly Property Application() As Application + Get + Return CType(Global.System.Windows.Application.Current, Application) + End Get + End Property + ''' + ''' Returns information about the host computer. + ''' + _ + Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.Computer + Get + Return s_Computer.GetInstance() + End Get + End Property + ''' + ''' Returns information for the current user. If you wish to run the application with the current + ''' Windows user credentials, call My.User.InitializeWithWindowsUser(). + ''' + _ + Friend ReadOnly Property User() As Global.Microsoft.VisualBasic.ApplicationServices.User + Get + Return s_User.GetInstance() + End Get + End Property + ''' + ''' Returns the application log. The listeners can be configured by the application's configuration file. + ''' + _ + Friend ReadOnly Property Log() As Global.Microsoft.VisualBasic.Logging.Log + Get + Return s_Log.GetInstance() + End Get + End Property + + ''' + ''' Returns the collection of Windows defined in the project. + ''' + _ + Friend ReadOnly Property Windows() As MyWindows + _ + Get + Return s_Windows.GetInstance() + End Get + End Property + _ + _ + Friend NotInheritable Class MyWindows + _ + Private Shared Function Create__Instance__(Of T As {New, Global.System.Windows.Window})(ByVal Instance As T) As T + If Instance Is Nothing Then + If s_WindowBeingCreated IsNot Nothing Then + If s_WindowBeingCreated.ContainsKey(GetType(T)) = True Then + Throw New Global.System.InvalidOperationException("The window cannot be accessed via My.Windows from the Window constructor.") + End If + Else + s_WindowBeingCreated = New Global.System.Collections.Hashtable() + End If + s_WindowBeingCreated.Add(GetType(T), Nothing) + Return New T() + s_WindowBeingCreated.Remove(GetType(T)) + Else + Return Instance + End If + End Function + _ + _ + Private Sub Dispose__Instance__(Of T As Global.System.Windows.Window)(ByRef instance As T) + instance = Nothing + End Sub + _ + _ + Public Sub New() + MyBase.New() + End Sub + Private Shared s_WindowBeingCreated As Global.System.Collections.Hashtable + Public Overrides Function Equals(ByVal o As Object) As Boolean + Return MyBase.Equals(o) + End Function + Public Overrides Function GetHashCode() As Integer + Return MyBase.GetHashCode + End Function + _ + _ + Friend Overloads Function [GetType]() As Global.System.Type + Return GetType(MyWindows) + End Function + Public Overrides Function ToString() As String + Return MyBase.ToString + End Function + End Class + End Module +End Namespace +Partial Class Application + Inherits Global.System.Windows.Application + _ + _ + Friend ReadOnly Property Info() As Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo + _ + Get + Return New Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo(Global.System.Reflection.Assembly.GetExecutingAssembly()) + End Get + End Property +End Class +#End If \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Resources.Designer.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Resources.Designer.vb new file mode 100644 index 0000000000..e7ecddcab6 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Resources.Designer.vb @@ -0,0 +1,62 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:$clrversion$ +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("$safeprojectname$.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set(ByVal value As Global.System.Globalization.CultureInfo) + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Resources.resx b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Resources.resx new file mode 100644 index 0000000000..af7dbebbac --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Settings.Designer.vb b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Settings.Designer.vb new file mode 100644 index 0000000000..51901f82e0 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + + Friend ReadOnly Property Settings() As Global.SDKSamples.My.MySettings + Get + Return Global.SDKSamples.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Settings.settings b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Settings.settings new file mode 100644 index 0000000000..40ed9fdbad --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/ProjectVB.vbproj b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/ProjectVB.vbproj new file mode 100644 index 0000000000..2198311849 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/ProjectVB.vbproj @@ -0,0 +1,136 @@ + + + + Debug + AnyCPU + {7D142ED4-D5D6-4680-BD9E-290CA944A377} + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} + WinExe + SDKSamples + ThreadExample + v4.8.1 + Custom + true + true + + + AnyCPU + true + full + true + true + true + bin\Debug\ + ThreadExample.xml + 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42314 + + + AnyCPU + pdbonly + false + false + true + false + true + bin\Release\ + ThreadExample.xml + 41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42314 + + + On + + + Binary + + + Off + + + On + + + + + + + + + + 4.0 + + + + + + + + + MSBuild:Compile + Designer + + + Application.xaml + Code + + + + + + + + + + + + + + + + + + + + + + + + MainWindow.xaml + + + Code + + + Microsoft.VisualBasic.WPF.MyExtension + 1.0.0.0 + + + True + True + Resources.resx + + + True + Settings.settings + True + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + + + SettingsSingleFileGenerator + Settings.Designer.vb + + + + + + + + Designer + MSBuild:Compile + + + + \ No newline at end of file diff --git a/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/snippets.5000.json b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/snippets.5000.json new file mode 100644 index 0000000000..da9ebf8da2 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/app-development/snippets/persist-and-restore-application-scope-properties/vb/snippets.5000.json @@ -0,0 +1,3 @@ +{ + "host": "visualstudio" +}