TextBlock.Foreground Eigenschap

Definitie

Hiermee haalt u het bestand op of stelt u deze Brush in op de tekstinhoud van de 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

Waarde van eigenschap

Het penseel dat wordt gebruikt om de tekstinhoud toe te passen. De standaardwaarde is Black.

Voorbeelden

In het volgende voorbeeld ziet u hoe u het Foreground kenmerk van een TextBlock element instelt.

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

In het volgende voorbeeld ziet u hoe u de eigenschap Foreground programmatisch instelt.

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

Opmerkingen

Zie voor een tabel met stalen die de beschikbare vooraf gedefinieerde kwastkleuren Brushestonen.

Alle Foreground instellingen op onderliggende elementen overschrijven deze instelling op het hoogste niveau.

Deze afhankelijkheidseigenschap heeft ook een gekoppeld eigenschapsgebruik. In XAML is <object TextBlock.Foreground="value".../>het gebruik, waarbij het object een objectelement is (meestal een stroomelement) in een TextBlock, en de waarde een tekenreeks is die wordt omgezet in een Brush implementatiewaarde. In code wordt het gebruik van gekoppelde eigenschappen ondersteund door GetForeground en SetForeground. Het gebruik van gekoppelde eigenschappen is niet gebruikelijk, omdat de meeste elementen die kunnen worden opgenomen in een TextBlock ondersteuning voor een analoge niet-gekoppelde Foreground eigenschap, die wordt TextBlock gebruikt voor rendering.

Informatie over afhankelijkheidseigenschappen

Item Waarde
Id-veld ForegroundProperty
Eigenschappen van metagegevens ingesteld op true AffectsRender, , SubPropertiesDoNotAffectRenderInherits

Van toepassing op