方法: グラデーションでシステム カラーを使用する
グラデーションでシステム カラーを使用するには、SystemColors クラスの *<SystemColor>*Color と *<SystemColor>*ColorKey の静的プロパティを使用して、カラーの参照を取得します。ここで、<SystemColor> は、目的のシステム カラーの名前です。 システム テーマが変更されたときに自動的に更新される動的参照を作成する場合は、*<SystemColor>*ColorKey プロパティを使用します。 それ以外の場合は、*<SystemColor>*Color プロパティを使用します。
例
次の例では、動的なシステム カラー リソースを使用して、グラデーションを作成します。
<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>
次の例では、静的なシステム カラー リソースを使用して、グラデーションを作成します。
<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>
関連項目
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示