TextBlock.Foreground Proprietà

Definizione

Recupera o imposta l'oggetto Brush da applicare al contenuto di testo di 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

Valore della proprietà

Pennello usato per applicare il contenuto di testo. Il valore predefinito è Black.

Esempio

Nell'esempio seguente viene illustrato come impostare l'attributo Foreground di un 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>

Nell'esempio seguente viene illustrato come impostare la Foreground proprietà a livello di codice.

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

Commenti

Per una tabella di campioni che mostrano i colori dei pennelli predefiniti disponibili, vedere Brushes.

Tutte Foreground le impostazioni sugli elementi figlio sostituiscono questa impostazione di primo livello.

Questa proprietà di dipendenza ha anche un utilizzo delle proprietà associate. In XAML l'utilizzo è <object TextBlock.Foreground="value".../>, dove l'oggetto è un elemento oggetto (in genere un elemento di flusso) contenuto all'interno di un TextBlockoggetto e il valore è una stringa che si risolve in un Brush valore di implementazione. Nel codice l'utilizzo delle proprietà associate è supportato da GetForeground e SetForeground. L'utilizzo della proprietà associata non è comune, perché la maggior parte degli elementi che possono essere contenuti in un supportano una TextBlock proprietà analoga non collegata Foreground , che usa per il TextBlock rendering.

Informazioni proprietà di dipendenza

Campo Identificatore ForegroundProperty
Proprietà dei metadati impostate su true AffectsRender, SubPropertiesDoNotAffectRender, Inherits

Si applica a