Class TextBlock
Provides a lightweight control for displaying small amounts of text.
Inherited Members
Namespace: System.Windows.Controls
Assembly: OpenSilver.dll
Syntax
public class TextBlock : FrameworkElement, IFrameworkElement, IUIElement, IDependencyObject
Examples
TextBlockName.Text = "Some text.";
Constructors
| Improve this Doc View SourceTextBlock()
Declaration
public TextBlock()
Fields
| Improve this Doc View SourceCharacterSpacingProperty
Identifies the CharacterSpacing dependency property.
Declaration
public static readonly DependencyProperty CharacterSpacingProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
FontFamilyProperty
Identifies the FontFamily dependency property.
Declaration
public static readonly DependencyProperty FontFamilyProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
FontSizeProperty
Identifies the FontSize dependency property.
Declaration
public static readonly DependencyProperty FontSizeProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
FontStretchProperty
Identifies the FontStretch dependency property.
Declaration
[NotImplemented]
public static readonly DependencyProperty FontStretchProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
FontStyleProperty
Identifies the FontStyle dependency property.
Declaration
public static readonly DependencyProperty FontStyleProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
FontWeightProperty
Identifies the FontWeight dependency property.
Declaration
public static readonly DependencyProperty FontWeightProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
ForegroundProperty
Identifies the Foreground dependency property.
Declaration
public static readonly DependencyProperty ForegroundProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
LineHeightProperty
Identifies the LineHeight dependency property.
Declaration
public static readonly DependencyProperty LineHeightProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
LineStackingStrategyProperty
Identifies the LineStackingStrategy dependency property.
Declaration
public static readonly DependencyProperty LineStackingStrategyProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
PaddingProperty
Identifies the Padding dependency property.
Declaration
public static readonly DependencyProperty PaddingProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
TextAlignmentProperty
Identifies the TextAlignment dependency property.
Declaration
public static readonly DependencyProperty TextAlignmentProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
TextDecorationsProperty
Identifies the TextDecorations dependency property.
Declaration
public static readonly DependencyProperty TextDecorationsProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
TextProperty
Identifies the Text dependency property.
Declaration
public static readonly DependencyProperty TextProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
TextTrimmingProperty
Identifies the TextTrimming dependency property.
Declaration
public static readonly DependencyProperty TextTrimmingProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
TextWrappingProperty
Identifies the TextWrapping dependency property.
Declaration
public static readonly DependencyProperty TextWrappingProperty
Field Value
Type | Description |
---|---|
DependencyProperty |
Properties
| Improve this Doc View SourceBaselineOffset
Returns a value by which each line of text is offset from a baseline.
Declaration
public double BaselineOffset { get; }
Property Value
Type | Description |
---|---|
System.Double | The amount by which each line of text is offset from the baseline, in device independent pixels. System.Double.NaN indicates that an optimal baseline offset is automatically calculated from the current font characteristics. The default is 0.0. |
CharacterSpacing
Gets or sets the distance between characters of text in the control measured in 1000ths of the font size.
Declaration
public int CharacterSpacing { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The distance between characters of text in the control measured in 1000ths of the font size. The default is 0. |
FontFamily
Gets or sets the preferred top-level font family for the text content in this element.
Declaration
public FontFamily FontFamily { get; set; }
Property Value
Type | Description |
---|---|
FontFamily | A FontFamily object that specifies the preferred font family, or a primary preferred font family with one or more fallback font families. For information about defaults, see the FontFamily class topic. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | FontFamily is null. |
FontSize
Gets or sets the font size for the text content in this element.
Declaration
public double FontSize { get; set; }
Property Value
Type | Description |
---|---|
System.Double | A non-negative value that specifies the font size, measured in pixels. The default is 11. |
FontSource
Gets or sets the font source that is applied to the text for rendering content.
Declaration
[NotImplemented]
public FontSource FontSource { get; set; }
Property Value
Type | Description |
---|---|
FontSource | The font source that is used to render content in the text box. The default is null. |
FontStretch
Gets or sets the font stretch for the text content in this element.
Declaration
[NotImplemented]
public FontStretch FontStretch { get; set; }
Property Value
Type | Description |
---|---|
FontStretch | The requested font stretch, which is a FontStretch that is obtained from one of the FontStretches property values. The default is Normal. |
FontStyle
Gets or sets the font style for the content in this element.
Declaration
public FontStyle FontStyle { get; set; }
Property Value
Type | Description |
---|---|
FontStyle | The requested font style, which is a FontStyle that is obtained from one of the FontStyles property values. The default is Normal. |
FontWeight
Gets or sets the top-level font weight for the TextBlock.
Declaration
public FontWeight FontWeight { get; set; }
Property Value
Type | Description |
---|---|
FontWeight | The requested font weight, which is a FontWeight that is obtained from one of the FontWeights property values. The default is Normal. |
Foreground
Declaration
public Brush Foreground { get; set; }
Property Value
Type | Description |
---|---|
Brush | The brush used to apply to the text contents. The default is a SolidColorBrush with a Color value of Black. |
Inlines
Gets the collection of inline text elements within a TextBlock.
Declaration
public InlineCollection Inlines { get; }
Property Value
Type | Description |
---|---|
InlineCollection | A collection that holds all inline text elements from the TextBlock.The default is an empty collection. |
LineHeight
Gets or sets the height of each line of content.
Declaration
public double LineHeight { get; set; }
Property Value
Type | Description |
---|---|
System.Double | The height of each line in pixels. A value of 0 indicates that the line height is determined automatically from the current font characteristics. The default is 0. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | LineHeight is set to a non-positive value. |
LineStackingStrategy
Gets or sets a value that indicates how a line box is determined for each line of text in the TextBlock.
Declaration
public LineStackingStrategy LineStackingStrategy { get; set; }
Property Value
Type | Description |
---|---|
LineStackingStrategy | A value that indicates how a line box is determined for each line of text in the TextBlock. The default is MaxHeight. |
Padding
Gets or sets a value that indicates the thickness of padding space between the boundaries of the content area and the content displayed by a TextBlock.
Declaration
public Thickness Padding { get; set; }
Property Value
Type | Description |
---|---|
Thickness | A Thickness structure that specifies the amount of padding to apply. |
Text
Gets or sets the text contents of a TextBlock.
Declaration
public string Text { get; set; }
Property Value
Type | Description |
---|---|
System.String | A string that specifies the text contents of this TextBlock. The default is an empty string. |
TextAlignment
Gets or sets a value that indicates the horizontal alignment of text content.
Declaration
public TextAlignment TextAlignment { get; set; }
Property Value
Type | Description |
---|---|
TextAlignment | The text alignment. The default is Left. |
TextDecorations
Gets or sets a value that specifies the text decorations that are applied to the content in a TextBlock element.
Declaration
public TextDecorationCollection TextDecorations { get; set; }
Property Value
Type | Description |
---|---|
TextDecorationCollection | A TextDecorationCollection, or null if no text decorations are applied. |
TextTrimming
Gets or sets the text trimming behavior to employ when content overflows the content area.
Declaration
public TextTrimming TextTrimming { get; set; }
Property Value
Type | Description |
---|---|
TextTrimming | One of the TextTrimming values that specifies the text trimming behavior to employ. The default is None. |
TextWrapping
Gets or sets how the TextBlock wraps text.
Declaration
public TextWrapping TextWrapping { get; set; }
Property Value
Type | Description |
---|---|
TextWrapping | A value that indicates how the TextBlock wraps text. The default is NoWrap. |
VisualChildrenCount
Declaration
protected override int VisualChildrenCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
Methods
| Improve this Doc View SourceArrangeOverride(Size)
Declaration
protected override Size ArrangeOverride(Size finalSize)
Parameters
Type | Name | Description |
---|---|---|
Size | finalSize |
Returns
Type | Description |
---|---|
Size |
Overrides
| Improve this Doc View SourceCreateDomElement(Object, out Object)
Declaration
public override object CreateDomElement(object parentRef, out object domElementWhereToPlaceChildren)
Parameters
Type | Name | Description |
---|---|---|
System.Object | parentRef | |
System.Object | domElementWhereToPlaceChildren |
Returns
Type | Description |
---|---|
System.Object |
Overrides
| Improve this Doc View SourceGetCharacterSpacing(DependencyObject)
Returns the value of the CharacterSpacing attached property for a specified dependency object.
Declaration
public static int GetCharacterSpacing(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object from which to retrieve the value of the CharacterSpacing attached property. |
Returns
Type | Description |
---|---|
System.Int32 | The current value of the CharacterSpacing attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetFontFamily(DependencyObject)
Returns the value of the FontFamily attached property for a specified dependency object.
Declaration
public static FontFamily GetFontFamily(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to retrieve the value of the FontFamily property. |
Returns
Type | Description |
---|---|
FontFamily | The current value of the FontFamily attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetFontSize(DependencyObject)
Returns the value of the FontSize attached property for a specified dependency object.
Declaration
public static double GetFontSize(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to retrieve the value of the FontSize property. |
Returns
Type | Description |
---|---|
System.Double | The current value of the FontSize attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetFontStretch(DependencyObject)
Returns the value of the FontStretch attached property for a specified dependency object.
Declaration
[NotImplemented]
public static FontStretch GetFontStretch(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to retrieve the value of the FontStretch property. |
Returns
Type | Description |
---|---|
FontStretch | The current value of the FontStretch attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetFontStyle(DependencyObject)
Returns the value of the FontStyle attached property for a specified dependency object.
Declaration
public static FontStyle GetFontStyle(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to retrieve the value of the FontStyle property. |
Returns
Type | Description |
---|---|
FontStyle | The current value of the FontStyle attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetFontWeight(DependencyObject)
Returns the value of the FontWeight attached property for a specified dependency object.
Declaration
public static FontWeight GetFontWeight(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to retrieve the value of the FontWeight property. |
Returns
Type | Description |
---|---|
FontWeight | The current value of the FontWeight attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetForeground(DependencyObject)
Returns the value of the Foreground attached property for a specified dependency object.
Declaration
public static Brush GetForeground(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to retrieve the value of the Foreground property. |
Returns
Type | Description |
---|---|
Brush | The current value of the Foreground attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetLineHeight(DependencyObject)
Returns the value of the LineHeight attached property for a specified dependency object.
Declaration
public static double GetLineHeight(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object from which to retrieve the value of the LineHeight property. |
Returns
Type | Description |
---|---|
System.Double | The current value of the LineHeight attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetLineStackingStrategy(DependencyObject)
Returns the value of the LineStackingStrategy attached property for a specified dependency object.
Declaration
public static LineStackingStrategy GetLineStackingStrategy(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object from which to retrieve the value of the LineStackingStrategy attached property. |
Returns
Type | Description |
---|---|
LineStackingStrategy | The current value of the LineStackingStrategy attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetTextAlignment(DependencyObject)
Returns the value of the TextAlignment attached property for a specified dependency object.
Declaration
public static TextAlignment GetTextAlignment(DependencyObject element)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object from which to retrieve the value of the TextAlignment property. |
Returns
Type | Description |
---|---|
TextAlignment | The current value of the TextAlignment attached property on the specified dependency object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
GetVisualChild(Int32)
Declaration
protected override UIElement GetVisualChild(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Returns
Type | Description |
---|---|
UIElement |
Overrides
| Improve this Doc View SourceINTERNAL_OnAttachedToVisualTree()
Declaration
protected override void INTERNAL_OnAttachedToVisualTree()
Overrides
| Improve this Doc View SourceMeasureOverride(Size)
Declaration
protected override Size MeasureOverride(Size availableSize)
Parameters
Type | Name | Description |
---|---|---|
Size | availableSize |
Returns
Type | Description |
---|---|
Size |
Overrides
| Improve this Doc View SourceOnCreateAutomationPeer()
Declaration
protected override AutomationPeer OnCreateAutomationPeer()
Returns
Type | Description |
---|---|
AutomationPeer |
Overrides
| Improve this Doc View SourceOnPropertyChanged(DependencyPropertyChangedEventArgs)
Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data.
Declaration
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
DependencyPropertyChangedEventArgs | e | Event data that will contain the dependency property identifier of interest, the property metadata for the type, and old and new values. |
Overrides
| Improve this Doc View SourceSetCharacterSpacing(DependencyObject, Int32)
Sets the value of the CharacterSpacing attached property on a specified dependency object.
Declaration
public static void SetCharacterSpacing(DependencyObject element, int value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object on which to set the value of the CharacterSpacing property. |
System.Int32 | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetFontFamily(DependencyObject, FontFamily)
Sets the value of the FontFamily attached property for a specified dependency object.
Declaration
public static void SetFontFamily(DependencyObject element, FontFamily value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to set the value of the FontFamily property. |
FontFamily | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetFontSize(DependencyObject, Double)
Sets the value of the FontSize attached property for a specified dependency object.
Declaration
public static void SetFontSize(DependencyObject element, double value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to set the value of the FontSize property. |
System.Double | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetFontStretch(DependencyObject, FontStretch)
Sets the value of the FontStretch attached property for a specified dependency object.
Declaration
[NotImplemented]
public static void SetFontStretch(DependencyObject element, FontStretch value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to set the value of the FontStretch property. |
FontStretch | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetFontStyle(DependencyObject, FontStyle)
Sets the value of the FontStyle attached property for a specified dependency object.
Declaration
public static void SetFontStyle(DependencyObject element, FontStyle value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to set the value of the FontStyle property. |
FontStyle | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetFontWeight(DependencyObject, FontWeight)
Sets the value of the FontWeight attached property for a specified dependency object.
Declaration
public static void SetFontWeight(DependencyObject element, FontWeight value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to set the value of the FontWeight property. |
FontWeight | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetForeground(DependencyObject, Brush)
Sets the value of the Foreground attached property for a specified dependency object.
Declaration
public static void SetForeground(DependencyObject element, Brush value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object for which to set the value of the Foreground property. |
Brush | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetLineHeight(DependencyObject, Double)
Sets the value of the LineHeight attached property for a specified dependency object.
Declaration
public static void SetLineHeight(DependencyObject element, double value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object on which to set the value of the LineHeight property. |
System.Double | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
System.ArgumentException | value is negative. |
SetLineStackingStrategy(DependencyObject, LineStackingStrategy)
Sets the value of the LineStackingStrategy attached property on a specified dependency object.
Declaration
public static void SetLineStackingStrategy(DependencyObject element, LineStackingStrategy value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object on which to set the value of the LineStackingStrategy property. |
LineStackingStrategy | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |
SetTextAlignment(DependencyObject, TextAlignment)
Sets the value of the TextAlignment attached property for a specified dependency object.
Declaration
public static void SetTextAlignment(DependencyObject element, TextAlignment value)
Parameters
Type | Name | Description |
---|---|---|
DependencyObject | element | The dependency object on which to set the value of the TextAlignment property. |
TextAlignment | value | The new value to set the property to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | element is null. |