TextEffectTarget 类

定义

使用 TextEffectResolver 对文本设置效果所产生的结果。 它由创建的 TextEffectDependencyObject 应设置为的 TextEffect 组成。

public ref class TextEffectTarget
public class TextEffectTarget
type TextEffectTarget = class
Public Class TextEffectTarget
继承
TextEffectTarget

示例

以下示例演示如何对文本应用 TranslateTransform文本 ScaleTransform效果和 RotateTransform 文本效果。 下面是示例的 XAML。

<Page  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SDKSample.TextEffectTargetExample"
    Title="TextBlock Properties Sample">

  <StackPanel>

    <RadioButton Click="teTranslate" Margin="5,0,5,0">TranslateTransform</RadioButton>
    <RadioButton Click="teScale" Margin="5,0,5,0">ScaleTransform</RadioButton>
    <RadioButton Click="teRotate" Margin="5,0,5,0">RotateTransform</RadioButton>

    <TextBlock Background="LightGray" TextWrapping="Wrap" Name="tb1">
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
      Nam laoreet dolor et dolor. Vestibulum quis nunc auctor ante dignissim venenatis. Curabitur wisi.
      Donec faucibus auctor ipsum. In fermentum dui.  Ut suscipit aliquam eros. Nullam elementum quam eu
      enim. Sed a purus id nisl imperdiet blandit. Cum sociis natoque penatibus et magnis dis parturient
      montes, nascetur ridiculus mus. Sed at quam.
    </TextBlock>

  </StackPanel>

</Page>

下面是该示例的隐藏代码。

using System;
using System.Windows;
using System.Collections;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Documents;

namespace SDKSample
{
    public partial class TextEffectTargetExample : Page
    {

        // Event handler for translating (moving) the text element.
        public void teTranslate(object sender, RoutedEventArgs e)
        {
            // Wipe out existing TextEffects on the TextBlock
            DisableTextEffects();

            TextEffect myEffect = new TextEffect();
            myEffect.PositionStart = 0;
            myEffect.PositionCount = 999;

            // Create a TranslateTransform that moves the TextBlock to an offset position of
            // 50,50.
            TranslateTransform myTranslateTransform = new TranslateTransform(50,50);
            myEffect.Transform = myTranslateTransform;

            // Apply the effect to the TextBlock
            EnableTextEffects(tb1, myEffect);
         }

         // Event handler for transforming the size of the text element.
        public void teScale(object sender, RoutedEventArgs e)
        {
            // Wipe out existing TextEffects on the TextBlock
            DisableTextEffects();

            TextEffect myEffect = new TextEffect();
            myEffect.PositionStart = 0;
            myEffect.PositionCount = 999;

            // Create a ScaleTransform that scales the TextBlock by 5.
            ScaleTransform myScaleTransform = new ScaleTransform(5,5);
            myEffect.Transform = myScaleTransform;

            // Apply the effect to the TextBlock
            EnableTextEffects(tb1, myEffect);
        }

        public void teRotate(object sender, RoutedEventArgs e)
        {
            // Wipe out existing TextEffects on the TextBlock
            DisableTextEffects();

            TextEffect myEffect = new TextEffect();
            myEffect.PositionStart = 0;
            myEffect.PositionCount = 999;

            // Create a ScaleTransform that rotates the text by 45 degrees.
            RotateTransform myRotateTransform = new RotateTransform(45);
            myEffect.Transform = myRotateTransform;

            // Apply the effect to the TextBlock
            EnableTextEffects(tb1, myEffect);
        }

        // Disable all existing text effects to make way for new ones.
        private void DisableTextEffects()
        {
            if (_textEffectTargets != null)
            {
                foreach (TextEffectTarget target in _textEffectTargets) 
                     target.Disable();
            }
        }

        // Enable TextEffectTargets and apply effect to TextBlock.
        private void EnableTextEffects(TextBlock tb, TextEffect effect)
        {
            _textEffectTargets = TextEffectResolver.Resolve(tb.ContentStart, tb.ContentEnd, effect);
            foreach (TextEffectTarget target in _textEffectTargets)
                target.Enable();           
        }

        private TextEffectTarget[] _textEffectTargets; 
    }
}

属性

Element

获取 DependencyObject 的目标 TextEffect

IsEnabled

获取一个值,该值确定是否对目标元素启用文本效果。

TextEffect

获取 TextEffectTextEffectTarget

方法

Disable()

对效果目标禁用 TextEffect

Enable()

对目标文本启用 TextEffect

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅