Condividi tramite


Procedura: utilizzare i colori di sistema in una sfumatura

Per usare un colore di sistema in una sfumatura, usare le proprietà statiche *SystemColor>*Color e *<SystemColor>*ColorKey della SystemColors classe per ottenere un riferimento al colore, dove< SystemColor> è il nome del colore di sistema desiderato.< Usare le proprietà *<SystemColor>*ColorKey quando si desidera creare un riferimento dinamico che viene aggiornato automaticamente man mano che cambia il tema di sistema. In caso contrario, utilizzare le proprietà *<SystemColor>*Color.

Esempio

L'esempio seguente usa risorse di colore di sistema dinamiche per creare una sfumatura.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://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>

L'esempio seguente usa risorse di colore di sistema statiche per creare una sfumatura.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://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>

Vedi anche