TextBlock.Foreground Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
public:
property System::Windows::Media::Brush ^ Foreground { System::Windows::Media::Brush ^ get(); void set(System::Windows::Media::Brush ^ value); };
public System.Windows.Media.Brush Foreground { get; set; }
member this.Foreground : System.Windows.Media.Brush with get, set
Public Property Foreground As Brush
Valor de Propriedade
O pincel usado para aplicar ao conteúdo do texto. A predefinição é Black.
Exemplos
O exemplo seguinte mostra como definir o Foreground atributo de um TextBlock elemento.
<TextBlock
Name="textBlock"
Background="AntiqueWhite"
Foreground="Navy"
FontFamily="Century Gothic"
FontSize="12"
FontStretch="UltraExpanded"
FontStyle="Italic"
FontWeight="UltraBold"
LineHeight="Auto"
Padding="5,10,5,10"
TextAlignment="Center"
TextWrapping="Wrap"
Typography.NumeralStyle="OldStyle"
Typography.SlashedZero="True"
>
<Run Background="LightGreen">Text run 1.</Run>
<LineBreak/><Run Background="LightBlue">Text run 2.</Run>
<LineBreak/><Run Background="LightYellow">Text run 3.</Run>
</TextBlock>
O exemplo a seguir mostra como definir a propriedade Foreground programaticamente.
TextBlock textBlock = new TextBlock(new Run("A bit of text content..."));
textBlock.Background = Brushes.AntiqueWhite;
textBlock.Foreground = Brushes.Navy;
textBlock.FontFamily = new FontFamily("Century Gothic");
textBlock.FontSize = 12;
textBlock.FontStretch = FontStretches.UltraExpanded;
textBlock.FontStyle = FontStyles.Italic;
textBlock.FontWeight = FontWeights.UltraBold;
textBlock.LineHeight = Double.NaN;
textBlock.Padding = new Thickness(5, 10, 5, 10);
textBlock.TextAlignment = TextAlignment.Center;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle;
textBlock.Typography.SlashedZero = true;
Dim textBlock As New TextBlock(New Run("A bit of text content..."))
textBlock.Background = Brushes.AntiqueWhite
textBlock.Foreground = Brushes.Navy
textBlock.FontFamily = New FontFamily("Century Gothic")
textBlock.FontSize = 12
textBlock.FontStretch = FontStretches.UltraExpanded
textBlock.FontStyle = FontStyles.Italic
textBlock.FontWeight = FontWeights.UltraBold
textBlock.LineHeight = Double.NaN
textBlock.Padding = New Thickness(5, 10, 5, 10)
textBlock.TextAlignment = TextAlignment.Center
textBlock.TextWrapping = TextWrapping.Wrap
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle
textBlock.Typography.SlashedZero = True
Observações
Para uma tabela de amostras que mostram as cores de pincel pré-definidas disponíveis, veja Brushes.
Quaisquer Foreground definições nos elementos filhos sobrepõem-se a esta definição de topo.
Esta propriedade de dependência também tem um uso associado à propriedade. Em XAML, a utilização é <object TextBlock.Foreground="value".../>, onde o objeto é um elemento de objeto (tipicamente um elemento de fluxo) contido num TextBlock, e o valor é uma cadeia que resolve para um Brush valor de implementação. No código, o uso da propriedade associada é suportado por GetForeground e SetForeground. O uso da propriedade anexada não é comum, porque a maioria dos elementos que podem ser contidos num TextBlock suporte a uma propriedade não anexada Foreground análoga, que o TextBlock uso é para renderização.
Informação de Propriedade de Dependência
| Item | Value |
|---|---|
| Campo identificador | ForegroundProperty |
Propriedades dos metadados definidas como true |
AffectsRender, SubPropertiesDoNotAffectRender, Inherits |