Application.Properties Property

 

Gets a collection of application-scope properties.

Namespace:   System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

Public ReadOnly Property Properties As IDictionary

Property Value

Type: System.Collections.IDictionary

An IDictionary that contains the application-scope properties.

Application exposes a dictionary via Properties which you can use to store application-scope properties. This allows you to share state amongst all code in an AppDomain in a thread-safe fashion, without the need to write your own state code.

Properties stored in Properties must be converted to the appropriate type returned.

TheProperties property is thread safe and is available from any thread.

The following example shows how create and use an application-scope property using Properties.

<Application x:Class="CSharp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"
    Startup="App_Startup"
    >
</Application>

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows

Namespace VisualBasic
    Partial Public Class App
        Inherits Application
        Private Sub App_Startup(ByVal sender As Object, ByVal e As StartupEventArgs)
            ' Parse command line arguments for "/SafeMode"
            Me.Properties("SafeMode") = False
            Dim i As Integer = 0
            Do While i <> e.Args.Length
                If e.Args(i).ToLower() = "/safemode" Then
                    Me.Properties("SafeMode") = True
                    Exit Do
                End If
                i += 1
            Loop
        End Sub
    End Class
End Namespace
<Window x:Class="CSharp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Loaded="MainWindow_Loaded"
    >
  <Grid>
  </Grid>
</Window>

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Controls

Namespace VisualBasic
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As EventArgs)
            ' Check for safe mode
            If CBool(Application.Current.Properties("SafeMode")) = True Then
                Me.Title &= " [SafeMode]"
            End If
        End Sub
    End Class
End Namespace

.NET Framework
Available since 3.0
Return to top
Show: