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

更新 : 2007 年 11 月

グラデーションでシステム カラーを使用するには、SystemColors クラスの静的プロパティ *<SystemColor>Color と <SystemColor>ColorKey を使用して、色に対する参照を取得します。<SystemColor> は、目的のシステム カラーの名前です。システム テーマが変更されると自動的に更新される動的な参照を作成するには、<SystemColor>ColorKey プロパティを使用します。それ以外の場合は、<SystemColor>*Color プロパティを使用します。

使用例

次の例では、動的なシステム カラー リソースを使用してグラデーションを作成します。

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

    <!-- Uses dynamic references to system colors to set
         the colors of gradient stops. 
         If these system colors change while this application
         is running, the gradient will be updated
         automatically.  -->
    <Button Content="Hello, World!">
      <Button.Background>
        <LinearGradientBrush>
          <LinearGradientBrush.GradientStops>
            <GradientStop Offset="0.0" 
              Color="{DynamicResource {x:Static SystemColors.DesktopColorKey}}" />
            <GradientStop Offset="1.0" 
              Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}" />
          </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
      </Button.Background>
    </Button>

  </StackPanel>
</Page>

次の例では、静的なシステム カラー リソースを使用してグラデーションを作成します。

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

    <!-- Uses static references to system colors to set
         the colors of gradient stops. 
         If these system colors change while this application
         is running, this button will not be updated until
         the page is loaded again. -->
    <Button Content="Hello, World!">
      <Button.Background>
        <LinearGradientBrush>
          <LinearGradientBrush.GradientStops>
            <GradientStop Offset="0.0" 
              Color="{x:Static SystemColors.DesktopColor}" />
            <GradientStop Offset="1.0" 
              Color="{x:Static SystemColors.ControlLightLightColor}" />
          </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
      </Button.Background>
    </Button>

  </StackPanel>
</Page>

この例は、より大きなサンプルの一部分です。サンプル全体については「システム ブラシおよびシステム カラーのサンプル」を参照してください。

参照

処理手順

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

概念

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

参照

SystemColors