Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 14 Application Settings, State, and Life Cycle.

Similar presentations


Presentation on theme: "Module 14 Application Settings, State, and Life Cycle."— Presentation transcript:

1 Module 14 Application Settings, State, and Life Cycle

2 Module Overview Managing Application State by Using Application Settings Managing the Application Life Cycle

3 Lesson 1: Managing Application State by Using Application Settings Understanding Application Settings Adding and Removing Application Settings Understanding the Settings Classes Reading and Writing Settings

4 User.config file App.config file Web service URL Connection string Understanding Application Settings Application Settings Settings class Application-scoped settings User-scoped settings

5 Adding and Removing Application Settings To add application settings by using the Project Designer: In the Settings grid, click a blank row In the Name column, type the name for the setting In the Type list, click the data type for the setting In the Scope list, click Application or User In the Value column, type a default value for the setting In the Settings grid, click a blank row In the Name column, type the name for the setting In the Type list, click the data type for the setting In the Scope list, click Application or User In the Value column, type a default value for the setting 1 1 3 3 2 2 To remove application settings: In the Settings grid, click the row for the setting to remove, and then press DELETE 5 5 4 4

6 Settings provider classes Settings classes public class MyUserSettings : ApplicationSettingsBase { [UserScopedSetting()] public Color BackgroundColor { get { return ((Color)this["BackgroundColor"]); } set { this["BackgroundColor"] = (Color)value; } } public class MyUserSettings : ApplicationSettingsBase { [UserScopedSetting()] public Color BackgroundColor { get { return ((Color)this["BackgroundColor"]); } set { this["BackgroundColor"] = (Color)value; } } Understanding the Settings Classes SettingsBase ApplicationSettingsBase SettingsProvider SettingsProviderAttribute XML LocalFileSettingsProvider MyUserSettings

7 Reading and Writing Settings... <ComboBox x:Name="Fonts" Grid.Column="1" ItemsSource="{x:Static Fonts.SystemFontFamilies}" SelectedItem="{Binding Source={x:Static p:Settings.Default}, Path=UserFont, Mode=TwoWay}">......... <ComboBox x:Name="Fonts" Grid.Column="1" ItemsSource="{x:Static Fonts.SystemFontFamilies}" SelectedItem="{Binding Source={x:Static p:Settings.Default}, Path=UserFont, Mode=TwoWay}">...... private void Ok_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.Save(); } private void Cancel_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.Reload(); } private void Ok_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.Save(); } private void Cancel_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.Reload(); }

8 Lesson 2: Managing the Application Life Cycle Understanding the Application Class Handling Application Events

9 Application definition: Understanding the Application Class <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="MyApplication.App" /> <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="MyApplication.App" /> Application services: Create and manage common application infrastructure Track and interact with the application life cycle Retrieve and process command-line parameters Share application-level properties and resources Detect and respond to unhandled exceptions Return exit codes Manage windows in stand-alone applications Track and manage navigation

10 Handling Application Events Application Object Application Code Run method Startup Deactivated SessionEnding Exit Shutdown method Activated Not canceled Canceled Explicit shutdown Operating System

11 Lab: Creating a Settings Dialog Box Exercise 1: Creating Application and User Settings by Using Visual Studio Exercise 2: Creating a Dialog Box Exercise 3: Reading and Writing Settings Exercise 4: Consuming Settings Properties Logon information Estimated time: 60 minutes

12 Lab Scenario You have been asked to update the Work Orders WPF application to remember the position and size of the main application window between sessions. You have also been asked to update the application to provide a settings dialog box to enable the user to configure the application. The settings dialog box should provide a way to view the database connection string details.

13 Lab Review Review Questions What is the difference between application and user settings? Which method do you use to show a Window class as a dialog box?

14 Module Review and Takeaways Review Questions


Download ppt "Module 14 Application Settings, State, and Life Cycle."

Similar presentations


Ads by Google