次の方法で共有


方法 : システム ブラシで領域を塗りつぶす

更新 : 2007 年 11 月

SystemColors クラスを使用すると、ControlBrushControlBrushKeyDesktopBrush などのシステム ブラシやシステム カラーにアクセスできます。システム ブラシは、指定したシステム カラーで領域を塗りつぶす SolidColorBrush オブジェクトです。システム ブラシは、常に純色の塗りつぶしを生成します。グラデーションを作成するためには使用できません。

システム ブラシは、静的なリソースとしても、動的なリソースとしても使用できます。アプリケーションの実行中にユーザーがシステム ブラシを変更したときにブラシを自動的に更新する場合は、動的リソースを使用します。それ以外の場合は、静的リソースを使用します。SystemColors クラスには、厳密な名前付け規則に従うさまざまな静的プロパティが含まれます。

  • *<SystemColor>*Brush

    指定したシステム カラーの SolidColorBrush に対する静的参照を取得します。

  • *<SystemColor>*BrushKey

    指定したシステム カラーの SolidColorBrush に対する動的参照を取得します。

  • *<SystemColor>*Color

    指定したシステム カラーの Color 構造体に対する静的参照を取得します。

  • *<SystemColor>*ColorKey

    指定したシステム カラーの Color 構造体に対する動的参照を取得します。

システム カラーは Color 構造体であり、ブラシの構成に使用できます。たとえば、LinearGradientBrush オブジェクトのグラデーション終了位置の Color プロパティにシステム カラーを設定することで、システム カラーを使用してグラデーションを作成できます。例については、「方法 : グラデーションでシステム カラーを使用する」を参照してください。

使用例

次の例では、動的システム ブラシ参照を使用して、ボタンの背景を設定しています。

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  WindowTitle="SystemColors Example" Background="White">  
  <StackPanel Margin="20">

    <!-- Uses a dynamic resource to set the 
         background of a button. 
         If the desktop brush changes while this application
         is running, this button will be updated. -->
    <Button 
      Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}" 
      Content="Hello, World!" />

  </StackPanel>
</Page>

次の例では、静的システム ブラシ参照を使用して、ボタンの背景を設定しています。

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  WindowTitle="SystemColors Example" Background="White">  
  <StackPanel Margin="20">

    <!-- Uses a static brush to set the
         background of a button. 
         If the desktop brush changes while this application
         is running, this button will not be updated until
         the page is loaded again. -->
    <Button 
      Background="{x:Static SystemColors.DesktopBrush}" 
      Content="Hello, World!"  /> 

  </StackPanel>
</Page>

グラデーションでのシステム カラーの使用方法を示す例については、「方法 : グラデーションでシステム カラーを使用する」を参照してください。

参照

処理手順

システム ブラシおよびシステム カラーのサンプル

方法 : グラデーションでシステム カラーを使用する

概念

純色およびグラデーションによる塗りつぶしの概要