TextBlock.Foreground Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
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 propiedad
Pincel usado para aplicar al contenido del texto. El valor predeterminado es Black.
Ejemplos
En el ejemplo siguiente se muestra cómo establecer el Foreground atributo de 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>
En el ejemplo siguiente se muestra cómo establecer la Foreground propiedad mediante programación.
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
Comentarios
Para obtener una tabla de muestras que muestren los colores de pincel predefinidos disponibles, vea Brushes.
Cualquier Foreground configuración de los elementos secundarios invalida esta configuración de nivel superior.
Esta propiedad de dependencia también tiene un uso de propiedad adjunta. En XAML, el uso es , donde el objeto es <object TextBlock.Foreground="value".../>un elemento de objeto (normalmente un elemento de flujo) contenido en un TextBlock, y el valor es una cadena que se resuelve en un Brush valor de implementación. En el código, el uso de la propiedad adjunta es compatible con GetForeground y SetForeground. El uso de la propiedad adjunta no es habitual, ya que la mayoría de los elementos que se pueden contener en una TextBlock propiedad no adjunta admiten Foreground una propiedad no adjunta análoga, que usa TextBlock para la representación.
Información de la propiedad dependency
| Elemento | Importancia |
|---|---|
| Campo identificador | ForegroundProperty |
Propiedades de metadatos establecidas en true |
AffectsRender, , SubPropertiesDoNotAffectRender, Inherits |