Gewusst wie: Verwenden von Systemfarben in einem Farbverlauf

Aktualisiert: November 2007

Zur Verwendung von Systemfarben in einem Farbverlauf erzeugen Sie mithilfe der statischen *<SystemColor>*Color- und *<SystemColor>*ColorKey-Eigenschaften der SystemColors-Klasse einen Verweis auf die Farbe, wobei <SystemColor> den Namen der gewünschten Systemfarbe darstellt. Verwenden Sie die *<SystemColor>*ColorKey-Eigenschaften, um einen dynamischen Verweis zu erstellen, der bei einer Änderung des Systemdesigns automatisch aktualisiert wird. Verwenden Sie andernfalls die *<SystemColor>*Color-Eigenschaften.

Beispiel

Im folgenden Beispiel wird ein Farbverlauf mithilfe dynamischer Systemfarbressourcen erstellt.

<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>

Im nächsten Beispiel wird ein Farbverlauf mithilfe statischer Systemfarbressourcen erstellt.

<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>

Dieses Beispiel ist Teil eines größeren Beispiels. Das vollständige Beispiel finden Sie unter Beispiel für Systempinsel und Systemfarben.

Siehe auch

Aufgaben

Gewusst wie: Zeichnen eines Bereichs mit einem Systempinsel

Konzepte

Übersicht über das Zeichnen mit Volltonfarben und Farbverläufen

Referenz

SystemColors