Compartilhar via


TextBlock.Foreground Propriedade

Definição

Obtém ou define a Brush aplicação ao conteúdo de texto do TextBlock.

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 da propriedade

O pincel usado para aplicar ao conteúdo do texto. O padrão é Black.

Exemplos

O exemplo a seguir 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

Comentários

Para obter uma tabela de amostras que mostram as cores de pincel predefinidas disponíveis, consulte Brushes.

Todas as Foreground configurações em elementos filho substituem essa configuração de nível superior.

Essa propriedade de dependência também tem um uso de propriedade anexada. No XAML, o uso é <object TextBlock.Foreground="value".../>, em que o objeto é um elemento de objeto (normalmente um elemento de fluxo) contido em um TextBlock, e o valor é uma cadeia de caracteres que resolve para um Brush valor de implementação. No código, o uso da propriedade anexada tem suporte GetForeground e SetForeground. O uso de propriedade anexada não é comum, pois a maioria dos elementos que podem ser contidos em uma TextBlock propriedade nãonattached Foreground análoga, que usa TextBlock para renderização.

Informações da propriedade Dependency

Item Valor
Campo identificador ForegroundProperty
Propriedades de metadados definidas como true AffectsRender, , SubPropertiesDoNotAffectRenderInherits

Aplica-se a