操作說明:使用系統筆刷繪製區域
類別 SystemColors 可讓您存取系統筆刷和色彩,例如 ControlBrush 、 ControlBrushKey 和 DesktopBrush 。 系統筆刷是物件 SolidColorBrush ,用來繪製具有指定系統色彩的區域。 系統筆刷只能產生純色填滿,因此無法用於產生漸層。
您可以將系統筆刷當作靜態或動態資源來使用。 當應用程式在執行時,如果您想要在使用者變更系統筆刷時自動更新筆刷,請使用動態資源;否則請使用靜態資源。 SystemColors 類別包含多種遵循嚴格命名慣例的靜態屬性:
* < SystemColor > *Brush
取得指定系統色彩的 靜態參考 SolidColorBrush 。
* < SystemColor > *BrushKey
取得指定系統色彩之 的 動態參考 SolidColorBrush 。
* < SystemColor > *Color
取得指定系統色彩結構的靜態參考 Color 。
* < SystemColor > *ColorKey
取得指定系統色彩結構的動態參考 Color 。
系統色彩是 Color 可用來設定筆刷的結構。 例如,您可以使用系統色彩來建立漸層,方法是使用系統色彩設定 Color 物件的漸層停駐點屬性 LinearGradientBrush 。 如需範例,請參閱在漸層中使用系統色彩。
範例
下列範例使用動態系統筆刷參考來設定按鈕的 Background。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://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>
下一個範例使用靜態系統筆刷參考來設定按鈕的 Background。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://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>
如需示範在漸層中使用系統色彩的範例,請參閱在漸層中使用系統色彩。
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應