Classe TextBlock
TOC
Comprimi il sommario
Espandi il sommario

TextBlock Class

Fornisce un controllo leggero per la visualizzazione di piccole quantità di testo.

Ereditarietà

Object
  DependencyObject
    UIElement
      FrameworkElement
        TextBlock

Sintassi


public sealed class TextBlock : FrameworkElement


<TextBlock ...>text</TextBlock>
-or-
<TextBlock>
  oneOrMoreInlineElements
</TextBlock>
-or-
<TextBlock .../>

XAML Values

text

Testo interno visualizzato nell'oggetto TextBlock. Questo testo diventa il valore della proprietà Text. Crea inoltre un singolo oggetto Run nuovo nella raccolta Inlines che contiene lo stesso testo.

oneOrMoreInlineElements

Uno o più elementi Run o LineBreak.

Attributi

ActivatableAttribute(NTDDI_WIN8)
ContentPropertyAttribute()
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.UI.Xaml.Controls.ITextBlockStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)
WebHostHiddenAttribute()

Membri

Il TextBlockClasse dispone di questi tipi di membri:

Costruttori

Il TextBlockClasse dispone di questi costruttori.

CostruttoreDescrizione
TextBlock Initializes a new instance of the TextBlock class.

 

Eventi

Il TextBlockClasse dispone di questi eventi.

EventoDescrizione
ContextMenuOpening Occurs when the system processes an interaction that displays a context menu.
DoubleTapped Occurs when an otherwise unhandled DoubleTap interaction occurs over the hit test area of this element. (Ereditato da UIElement)
DragEnter Occurs when the input system reports an underlying drag event with this element as the target. (Ereditato da UIElement)
DragLeave Occurs when the input system reports an underlying drag event with this element as the origin. (Ereditato da UIElement)
DragOver Occurs when the input system reports an underlying drag event with this element as the potential drop target. (Ereditato da UIElement)
Drop Occurs when the input system reports an underlying drop event with this element as the drop target. (Ereditato da UIElement)
GotFocus Occurs when a UIElement receives focus. (Ereditato da UIElement)
Holding Occurs when an otherwise unhandled Hold interaction occurs over the hit test area of this element. (Ereditato da UIElement)
KeyDown Occurs when a keyboard key is pressed while the UIElement has focus. (Ereditato da UIElement)
KeyUp Occurs when a keyboard key is released while the UIElement has focus. (Ereditato da UIElement)
LayoutUpdated Occurs when the layout of the visual tree changes. (Ereditato da FrameworkElement)
Loaded Occurs when a FrameworkElement has been constructed and added to the object tree, and is ready for interaction. (Ereditato da FrameworkElement)
LostFocus Occurs when a UIElement loses focus. (Ereditato da UIElement)
ManipulationCompleted Occurs when a manipulation on the UIElement is complete. (Ereditato da UIElement)
ManipulationDelta Occurs when the input device changes position during a manipulation. (Ereditato da UIElement)
ManipulationInertiaStarting Occurs when the input device loses contact with the UIElement object during a manipulation and inertia begins. (Ereditato da UIElement)
ManipulationStarted Occurs when an input device begins a manipulation on the UIElement. (Ereditato da UIElement)
ManipulationStarting Occurs when the manipulation processor is first created. (Ereditato da UIElement)
PointerCanceled Occurs when a pointer that made contact abnormally loses contact. (Ereditato da UIElement)
PointerCaptureLost Occurs when pointer capture previously held by this element moves to another element or elsewhere. (Ereditato da UIElement)
PointerEntered Occurs when a pointer enters the hit test area of this element. (Ereditato da UIElement)
PointerExited Occurs when a pointer leaves the hit test area of this element. (Ereditato da UIElement)
PointerMoved Occurs when a pointer moves while the pointer remains within the hit test area of this element. (Ereditato da UIElement)
PointerPressed Occurs when the pointer device initiates a Press action within this element. (Ereditato da UIElement)
PointerReleased Occurs when the pointer device that previously initiated a Press action is released, while within this element. (Ereditato da UIElement)
PointerWheelChanged Occurs when the delta value of a pointer wheel changes. (Ereditato da UIElement)
RightTapped Occurs when a right-tap input stimulus happens while the pointer is over the element. (Ereditato da UIElement)
SelectionChanged Occurs when the text selection has changed.
SizeChanged Occurs when either the ActualHeight or the ActualWidth property changes value on a FrameworkElement. (Ereditato da FrameworkElement)
Tapped Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of this element. (Ereditato da UIElement)
Unloaded Occurs when this object is no longer connected to the main object tree. (Ereditato da FrameworkElement)

 

Metodi

The TextBlock Classe dispone di questi metodi. Eredita inoltre i metodi da Object Classe.

MetodoDescrizione
AddHandler Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked even if the event is handled elsewhere. (Ereditato da UIElement)
Arrange Positions child objects and determines a size for a UIElement. Parent objects that implement custom layout for their child elements should call this method from their layout override implementations to form a recursive layout update. (Ereditato da UIElement)
ArrangeOverride Provides the behavior for the Arrange pass of layout. Classes can override this method to define their own Arrange pass behavior. (Ereditato da FrameworkElement)
CapturePointer Sets pointer capture to a UIElement. Once captured, only the element that has capture will fire pointer-related events. (Ereditato da UIElement)
ClearValue Clears the local value of a dependency property. (Ereditato da DependencyObject)
FindName Retrieves an object that has the specified identifier name. (Ereditato da FrameworkElement)
FindSubElementsForTouchTargeting Enables a UIElement subclass to expose child elements that assist with resolving touch targeting. (Ereditato da UIElement)
Focus Focuses the TextBlock, as if it were a conventionally focusable control.
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Ereditato da DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Ereditato da DependencyObject)
InvalidateArrange Invalidates the arrange state (layout) for a UIElement. After the invalidation, the UIElement will have its layout updated, which will occur asynchronously. (Ereditato da UIElement)
InvalidateMeasure Invalidates the measurement state (layout) for a UIElement. (Ereditato da UIElement)
Measure Updates the DesiredSize of a UIElement. Typically, objects that implement custom layout for their layout children call this method from their own MeasureOverride implementations to form a recursive layout update. (Ereditato da UIElement)
MeasureOverride Provides the behavior for the Measure pass of the layout cycle. Classes can override this method to define their own Measure pass behavior. (Ereditato da FrameworkElement)
OnApplyTemplate Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class. (Ereditato da FrameworkElement)
OnCreateAutomationPeer When implemented in a derived class, returns class-specific AutomationPeer implementations for the Microsoft UI Automation infrastructure. (Ereditato da UIElement)
OnDisconnectVisualChildren Override this method to implement how layout and logic should behave when items are removed from a class-specific content or children property. (Ereditato da UIElement)
ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Ereditato da DependencyObject)
ReleasePointerCapture Releases pointer captures for capture of one specific pointer by this UIElement. (Ereditato da UIElement)
ReleasePointerCaptures Releases all pointer captures held by this element. (Ereditato da UIElement)
RemoveHandler Removes the specified routed event handler from this UIElement. Typically the handler in question was added by AddHandler. (Ereditato da UIElement)
Select Selects a range of text in the TextBlock.
SelectAll Selects the entire contents in the TextBlock.
SetBinding Attaches a binding to a FrameworkElement, using the provided binding object. (Ereditato da FrameworkElement)
SetValue Sets the local value of a dependency property on a DependencyObject. (Ereditato da DependencyObject)
TransformToVisual Returns a transform object that can be used to transform coordinates from the UIElement to the specified object. (Ereditato da UIElement)
UpdateLayout Ensures that all positions of child objects of a UIElement are properly updated for layout. (Ereditato da UIElement)

 

Proprietà

TextBlockClasse dispone di queste proprietà.

ProprietàTipo accessoDescrizione

ActualHeight

Sola letturaGets the rendered height of a FrameworkElement. (Ereditato da FrameworkElement)

ActualWidth

Sola letturaGets the rendered width of a FrameworkElement. (Ereditato da FrameworkElement)

AllowDrop

Lettura/scritturaGets or sets a value that determines whether this UIElement can be a drop target for purposes of drag-and-drop operations. (Ereditato da UIElement)

BaselineOffset

Sola letturaReturns a value by which each line of text is offset from a baseline.

BaseUri

Sola letturaGets a Uniform Resource Identifier (URI) that represents the base Uniform Resource Identifier (URI) for an XAML-constructed object at XAML load time. This property is useful for Uniform Resource Identifier (URI) resolution at run time. (Ereditato da FrameworkElement)

CacheMode

Lettura/scritturaGets or sets a value that indicates that rendered content should be cached as a composited bitmap when possible. (Ereditato da UIElement)

CharacterSpacing

Lettura/scritturaGets or sets the uniform spacing between characters, in units of 1/1000 of an em.

CharacterSpacingProperty

Sola letturaIdentifies the CharacterSpacing dependency property.

Clip

Lettura/scritturaGets or sets the RectangleGeometry used to define the outline of the contents of a UIElement. (Ereditato da UIElement)

ContentEnd

Sola letturaGets a TextPointer object for the end of text content in the TextBlock.

ContentStart

Sola letturaGets a TextPointer object for the start of text content in the TextBlock.

DataContext

Lettura/scritturaGets or sets the data context for a FrameworkElement when it participates in data binding. (Ereditato da FrameworkElement)

DesiredSize

Sola letturaGets the size that this UIElement computed during the measure pass of the layout process. (Ereditato da UIElement)

Dispatcher

Sola letturaGets the CoreDispatcher that this object is associated with. (Ereditato da DependencyObject)

FlowDirection

Lettura/scritturaGets or sets the direction in which text and other UI elements flow within any parent element that controls their layout. This property can be set to either LeftToRight or RightToLeft. Setting FlowDirection to RightToLeft on any element sets the alignment to the right, the reading order to right-to-left and the layout of the control to flow from right to left. (Ereditato da FrameworkElement)

FontFamily

Lettura/scritturaGets or sets the preferred top-level font family for the text content in this element.

FontFamilyProperty

Sola letturaIdentifies the FontFamily dependency property.

FontSize

Lettura/scritturaGets or sets the font size for the text content in this element.

FontSizeProperty

Sola letturaIdentifies the FontSize dependency property.

FontStretch

Lettura/scritturaGets or sets the font stretch for the text content in this element.

FontStretchProperty

Sola letturaIdentifies the FontStretch dependency property.

FontStyle

Lettura/scritturaGets or sets the font style for the content in this element.

FontStyleProperty

Sola letturaIdentifies the FontStyle dependency property.

FontWeight

Lettura/scritturaGets or sets the top-level font weight for the TextBlock.

FontWeightProperty

Sola letturaIdentifies the FontWeight dependency property.

Foreground

Lettura/scritturaGets or sets the Brush to apply to the text contents of the TextBlock.

ForegroundProperty

Sola letturaIdentifies the Foreground dependency property.

Height

Lettura/scritturaGets or sets the suggested height of a FrameworkElement. (Ereditato da FrameworkElement)

HorizontalAlignment

Lettura/scritturaGets or sets the horizontal alignment characteristics that are applied to a FrameworkElement when it is composed in a layout parent, such as a panel or items control. (Ereditato da FrameworkElement)

Inlines

Sola letturaGets the collection of inline text elements within a TextBlock.

IsDoubleTapEnabled

Lettura/scritturaGets or sets a value that determines whether the DoubleTapped event can originate from that element. (Ereditato da UIElement)

IsHitTestVisible

Lettura/scritturaGets or sets whether the contained area of this UIElement can return true values for hit testing. (Ereditato da UIElement)

IsHoldingEnabled

Lettura/scritturaGets or sets a value that determines whether the Holding event can originate from that element. (Ereditato da UIElement)

IsRightTapEnabled

Lettura/scritturaGets or sets a value that determines whether the RightTapped event can originate from that element. (Ereditato da UIElement)

IsTapEnabled

Lettura/scritturaGets or sets a value that determines whether the Tapped event can originate from that element. (Ereditato da UIElement)

IsTextSelectionEnabled

Lettura/scritturaGets or sets a value that indicates whether text selection is enabled in the TextBlock, either through user action or calling selection-related API.

IsTextSelectionEnabledProperty

Sola letturaIdentifies the IsTextSelectionEnabled dependency property.

Language

Lettura/scritturaGets or sets localization/globalization language information that applies to a FrameworkElement, and also to all child elements of the current FrameworkElement in the object representation and in UI. (Ereditato da FrameworkElement)

LineHeight

Lettura/scritturaGets or sets the height of each line of content.

LineHeightProperty

Sola letturaIdentifies the LineHeight dependency property.

LineStackingStrategy

Lettura/scritturaGets or sets a value that indicates how a line box is determined for each line of text in the TextBlock.

LineStackingStrategyProperty

Sola letturaIdentifies the LineStackingStrategy dependency property.

ManipulationMode

Lettura/scritturaGets or sets the ManipulationModes value used for UIElement behavior and interaction with gestures. (Ereditato da UIElement)

Margin

Lettura/scritturaGets or sets the outer margin of a FrameworkElement. (Ereditato da FrameworkElement)

MaxHeight

Lettura/scritturaGets or sets the maximum height constraint of a FrameworkElement. (Ereditato da FrameworkElement)

MaxWidth

Lettura/scritturaGets or sets the maximum width constraint of a FrameworkElement. (Ereditato da FrameworkElement)

MinHeight

Lettura/scritturaGets or sets the minimum height constraint of a FrameworkElement. (Ereditato da FrameworkElement)

MinWidth

Lettura/scritturaGets or sets the minimum width constraint of a FrameworkElement. (Ereditato da FrameworkElement)

Name

Lettura/scritturaGets or sets the identifying name of the object. When a XAML processor creates the object tree from XAML markup, run-time code can refer to the XAML-declared object by this name. (Ereditato da FrameworkElement)

Opacity

Lettura/scritturaGets or sets the degree of the object's opacity. (Ereditato da UIElement)

Padding

Lettura/scritturaGets 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.

PaddingProperty

Sola letturaIdentifies the Padding dependency property.

Parent

Sola letturaGets the parent object of this FrameworkElement in the object tree. (Ereditato da FrameworkElement)

PointerCaptures

Sola letturaGets the set of all captured pointers, represented as Pointer values. (Ereditato da UIElement)

Projection

Lettura/scritturaGets or sets the perspective projection (3-D effect) to apply when rendering this element. (Ereditato da UIElement)

RenderSize

Sola letturaGets the final render size of a UIElement. (Ereditato da UIElement)

RenderTransform

Lettura/scritturaGets or sets transform information that affects the rendering position of a UIElement. (Ereditato da UIElement)

RenderTransformOrigin

Lettura/scritturaGets or sets the origin point of any possible render transform declared by RenderTransform, relative to the bounds of the UIElement. (Ereditato da UIElement)

Resources

Lettura/scritturaGets the locally defined resource dictionary. In XAML, you can establish resource items as child object elements of a frameworkElement.Resources property element, through XAML implicit collection syntax. (Ereditato da FrameworkElement)

SelectedText

Sola letturaGets a text range of selected text.

SelectedTextProperty

Sola letturaIdentifies the SelectedText dependency property.

SelectionEnd

Sola letturaGets the end position of the text selected in the TextBlock.

SelectionStart

Sola letturaGets the starting position of the text selected in the TextBlock.

Style

Lettura/scritturaGets or sets an instance Style that is applied for this object during layout and rendering. (Ereditato da FrameworkElement)

Tag

Lettura/scritturaGets or sets an arbitrary object value that can be used to store custom information about this object. (Ereditato da FrameworkElement)

Text

Lettura/scritturaGets or sets the text contents of a TextBlock.

TextAlignment

Lettura/scritturaGets or sets a value that indicates the horizontal alignment of text content.

TextAlignmentProperty

Sola letturaIdentifies the TextAlignment dependency property.

TextProperty

Sola letturaIdentifies the Text dependency property.

TextTrimming

Lettura/scritturaGets or sets the text trimming behavior to employ when content overflows the content area.

TextTrimmingProperty

Sola letturaIdentifies the TextTrimming dependency property.

TextWrapping

Lettura/scritturaGets or sets how the TextBlock wraps text.

TextWrappingProperty

Sola letturaIdentifies the TextWrapping dependency property.

Transitions

Lettura/scritturaGets or sets the collection of Transition style elements that apply to a UIElement. (Ereditato da UIElement)

Triggers

Sola letturaGets the collection of triggers for animations that are defined for a FrameworkElement. Not commonly used. (Ereditato da FrameworkElement)

UseLayoutRounding

Lettura/scritturaGets or sets a value that determines whether rendering for the object and its visual subtree should use rounding behavior that aligns rendering to whole pixels. (Ereditato da UIElement)

VerticalAlignment

Lettura/scritturaGets or sets the vertical alignment characteristics that are applied to a FrameworkElement when it is composed in a parent object such as a panel or items control. (Ereditato da FrameworkElement)

Visibility

Lettura/scritturaGets or sets the visibility of a UIElement. A UIElement that is not visible is not rendered and does not communicate its desired size to layout. (Ereditato da UIElement)

Width

Lettura/scritturaGets or sets the width of a FrameworkElement. (Ereditato da FrameworkElement)

 

Esempi

Nell'esempio seguente viene illustrato come utilizzare la proprietà LineStackingStrategy per determinare la modalità di creazione dei riquadri per le righe di testo di un oggetto TextBlock. Il primo TextBlock ha un valore LineStackingStrategy pari a MaxHeight e il secondo TextBlock ha un valore pari a BlockLineHeight.


<StackPanel>

<!-- This TextBlock has a LineStackingStrategy set to "MaxHeight". -->
<TextBlock FontFamily="Verdana"
           LineStackingStrategy="MaxHeight" 
           LineHeight="10" 
           Width="500" 
           TextWrapping="Wrap" >
    Use the <Run FontSize="30">LineStackingStrategy</Run> property to determine how a line box is
    created for each line. A value of <Run FontSize="20">MaxHeight</Run> specifies that the stack
    height is the smallest value that contains all the inline elements on that line when those
    elements are properly aligned. A value of <Run FontSize="20">BlockLineHeight</Run> specifies
    that the stack height is determined by the block element LineHeight property value.
</TextBlock>

    <!-- With a margin pushing down 20 pixels, draw a line just above the second textblock. -->
    <!-- The fonts will reach above the LineHeight size and over the line. -->
<StackPanel Margin="0,20,0,0" HorizontalAlignment="Center">
    <Line Stroke="Green"  X2="500" />
</StackPanel>

            <!-- Here is the same TextBlock but the LineStackingStrategy is set to "BlockLineHeight". -->
<TextBlock FontFamily="Verdana"
           LineStackingStrategy="BlockLineHeight" 
           LineHeight="10" 
           Width="500" 
           TextWrapping="Wrap">
    Use the <Run FontSize="30">LineStackingStrategy</Run> property to determine how a line box is
    created for each line. A value of <Run FontSize="20">MaxHeight</Run> specifies that the stack
    height is the smallest value that contains all the inline elements on that line when those
    elements are properly aligned. A value of <Run FontSize="20">BlockLineHeight</Run> specifies
    that the stack height is determined by the block element LineHeight property value.
</TextBlock>

</StackPanel>


Requisiti

Client minimo supportato

Windows 8 [solo app di Windows Store]

Server minimo supportato

Windows Server 2012 [solo app di Windows Store]

Spazio dei nomi

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadati

Windows.winmd

Vedi anche

FrameworkElement

 

 

Mostra:
© 2016 Microsoft