Application.Properties Application.Properties Application.Properties Application.Properties Property

定義

アプリケーション スコープのプロパティのコレクションを取得します。Gets a collection of application-scope properties.

public:
 property System::Collections::IDictionary ^ Properties { System::Collections::IDictionary ^ get(); };
public System.Collections.IDictionary Properties { get; }
member this.Properties : System.Collections.IDictionary
Public ReadOnly Property Properties As IDictionary

プロパティ値

アプリケーション スコープのプロパティを格納している IDictionaryAn IDictionary that contains the application-scope properties.

次の例は、を使用して、アプリケーションスコープのプロパティPropertiesを作成して使用する方法を示しています。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>
using System;
using System.Windows;

namespace CSharp
{
    public partial class App : Application
    {
        void App_Startup(object sender, StartupEventArgs e)
        {
            // Parse command line arguments for "/SafeMode"
            this.Properties["SafeMode"] = false;
            for (int i = 0; i != e.Args.Length; ++i)
            {
                if (e.Args[i].ToLower() == "/safemode")
                {
                    this.Properties["SafeMode"] = true;
                    break;
                }
            }
        }
    }
}

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>
using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        void MainWindow_Loaded(object sender, EventArgs e)
        {
            // Check for safe mode
            if ((bool)Application.Current.Properties["SafeMode"] == true)
            {
                this.Title += " [SafeMode]";
            }
        }
    }
}

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

注釈

ApplicationアプリケーションスコープのプロパティPropertiesを格納するために使用できるディクショナリを公開します。Application exposes a dictionary via Properties which you can use to store application-scope properties. これにより、独自の状態コードを記述しAppDomainなくても、スレッドセーフな方法でのすべてのコード間で状態を共有できます。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格納されているプロパティは、返される適切な型に変換される必要があります。Properties stored in Properties must be converted to the appropriate type returned.

Propertiesプロパティはスレッドセーフであり、任意のスレッドから使用できます。The Properties property is thread safe and is available from any thread.

適用対象

こちらもご覧ください