操作說明:使用純色繪製區域
若要使用純色繪製區域,您可以使用預先定義的系統筆刷,例如 Red 或 Blue ,或者您可以使用 Alpha、紅色、綠色和藍色值來建立新的 SolidColorBrush 並描述其 Color 。 在 XAML 中,您也可以使用十六進位標記法來以純色繪製區域。
下列範例會使用這些技術來繪製 Rectangle 藍色。
範例
使用預先定義的筆刷
在下列範例中,會使用預先定義的筆刷 Blue 繪製矩形藍色。
<Rectangle Width="50" Height="50" Fill="Blue" />
// Create a rectangle and paint it with
// a predefined brush.
Rectangle myPredefinedBrushRectangle = new Rectangle();
myPredefinedBrushRectangle.Width = 50;
myPredefinedBrushRectangle.Height = 50;
myPredefinedBrushRectangle.Fill = Brushes.Blue;
使用十六進位標記法
下一個範例會使用 8 位數的十六進位標記法將矩形繪製成藍色。
<!-- Note that the first two characters "FF" of the 8-digit
value is the alpha which controls the transparency of
the color. Therefore, to make a completely transparent
color (invisible), use "00" for those digits (e.g. #000000FF). -->
<Rectangle Width="50" Height="50" Fill="#FF0000FF" />
使用 ARGB 值
下一個範例會 SolidColorBrush 建立 ,並描述其 Color 使用藍色的 ARGB 值。
<Rectangle Width="50" Height="50">
<Rectangle.Fill>
<SolidColorBrush>
<SolidColorBrush.Color>
<!-- Describes the brush's color using
RGB values. Each value has a range of 0-255.
R is for red, G is for green, and B is for blue.
A is for alpha which controls transparency of the
color. Therefore, to make a completely transparent
color (invisible), use a value of 0 for Alpha. -->
<Color A="255" R="0" G="0" B="255" />
</SolidColorBrush.Color>
</SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
Rectangle myRgbRectangle = new Rectangle();
myRgbRectangle.Width = 50;
myRgbRectangle.Height = 50;
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
// Describes the brush's color using RGB values.
// Each value has a range of 0-255.
mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);
myRgbRectangle.Fill = mySolidColorBrush;
如需描述色彩的其他方式,請參閱 Color 結構。
相關主題
如需和其他範例的詳細資訊 SolidColorBrush ,請參閱 使用純色和漸層 概觀小畫家。
此程式碼範例是提供給 類別之較大範例的 SolidColorBrush 一部分。 如需完整的範例,請參閱 Brush 範例。
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應