TextBlock.TextEffects 属性

定义

获取或设置要应用于此元素中的文本内容的效果。

public:
 property System::Windows::Media::TextEffectCollection ^ TextEffects { System::Windows::Media::TextEffectCollection ^ get(); void set(System::Windows::Media::TextEffectCollection ^ value); };
public System.Windows.Media.TextEffectCollection TextEffects { get; set; }
member this.TextEffects : System.Windows.Media.TextEffectCollection with get, set
Public Property TextEffects As TextEffectCollection

属性值

TextEffectCollection

一个 TextEffectCollection,其中包含一个或多个 TextEffect 对象,这些对象定义了要应用于 TextBlock 的文本的效果。 默认值为 null(不应用任何效果)。

示例

下面的示例演示如何创建简单的文本效果并将其应用于文本 TextBlock

// Create and configure a simple color animation sequence.  Timespan is in 100ns ticks.
ColorAnimation blackToWhite = new ColorAnimation(Colors.White, Colors.Black, new Duration(new TimeSpan(100000)));
blackToWhite.AutoReverse = true;
blackToWhite.RepeatBehavior = RepeatBehavior.Forever;

// Create a new brush and apply the color animation.
SolidColorBrush scb = new SolidColorBrush(Colors.Black);
scb.BeginAnimation(SolidColorBrush.ColorProperty, blackToWhite);

// Create a new TextEffect object; set foreground brush to the previously created brush.
TextEffect tfe = new TextEffect();
tfe.Foreground = scb;
// Range of text to apply effect to (all).
tfe.PositionStart = 0;
tfe.PositionCount = int.MaxValue;

// Create a new TextBlock with some text.
TextBlock textBlock = new TextBlock();
textBlock.Text = "Text that flickers...";

// The TextEffects property is null (no collection) by default.  Create a new one.
textBlock.TextEffects = new TextEffectCollection();

// Add the previously created effect to the TextEffects collection.
textBlock.TextEffects.Add(tfe);
' Create and configure a simple color animation sequence.  Timespan is in 100ns ticks.
Dim blackToWhite As New ColorAnimation(Colors.White, Colors.Black, New Duration(New TimeSpan(100000)))
blackToWhite.AutoReverse = True
blackToWhite.RepeatBehavior = RepeatBehavior.Forever

' Create a new brush and apply the color animation.
Dim scb As New SolidColorBrush(Colors.Black)
scb.BeginAnimation(SolidColorBrush.ColorProperty, blackToWhite)

' Create a new TextEffect object; set foreground brush to the previously created brush.
Dim tfe As New TextEffect()
tfe.Foreground = scb
' Range of text to apply effect to (all).
tfe.PositionStart = 0
tfe.PositionCount = Integer.MaxValue

' Create a new TextBlock with some text.
Dim textBlock As New TextBlock()
textBlock.Text = "Text that flickers..."

' The TextEffects property is null (no collection) by default.  Create a new one.
textBlock.TextEffects = New TextEffectCollection()

' Add the previously created effect to the TextEffects collection.
textBlock.TextEffects.Add(tfe)

注解

默认情况下,此属性设置为 null 且没有 TextEffectCollection 与之关联的属性。 在添加任何文本效果之前,请创建新的 TextEffectCollection 文本效果并将其分配给此属性。

依赖项属性信息

标识符字段 TextEffectsProperty
元数据属性设置为 true AffectsRender

适用于