IconElement.Foreground 屬性

定義

取得或設定描述前景色彩的筆刷。

public:
 property Brush ^ Foreground { Brush ^ get(); void set(Brush ^ value); };
Brush Foreground();

void Foreground(Brush value);
public Brush Foreground { get; set; }
var brush = iconElement.foreground;
iconElement.foreground = brush;
Public Property Foreground As Brush
<icon Foreground="{StaticResource resourceName}"/>
- or -
<icon Foreground="colorString"/>

屬性值

繪製控制項前景的筆刷。 默認值為 null, (null 筆刷) 評估為 透明 以進行轉譯。 不過,此值通常是由運行時間的默認系統資源所設定,這會系結至使用中的主題和其他設定。

範例

此範例顯示 AppBarButton ,其使用 SymbolIcon 並將其Foreground設定為「Green」。

<AppBarButton Label="Accept">
    <AppBarButton.Icon>
        <SymbolIcon Symbol="Accept" Foreground="Green"/>
    </AppBarButton.Icon>
</AppBarButton>

備註

您可以在 AppBarButtonIconElement 衍生圖示上設定 Foreground 屬性。 如果您在 AppBarButton 上設定前景,它只會套用至預設視覺狀態。 它不會套用至 AppBarButton 樣本中定義的其他視覺狀態,例如 MouseOver。 如果您在 IconElement 衍生圖示上設定前景,色彩會套用至所有視覺狀態。

Foreground 值的唯一有效 Brush 類型是 SolidColorBrush。 如果您嘗試使用未宣告純色的筆刷,則會在運行時間忽略此值,並以白色或黑色 的 SolidColorBrush 取代此值,視目前的主題而定。

前景會取代 BitmapIcon.UriSource 來源檔案中的色彩資訊。 來源影像中的任何非透明圖元會取代為前景色彩。

適用於

另請參閱