如何在故事板中设置包含新行字符的文本



要将"n"替换为新的行字符

<VisualState x:Name="Snapped">
    <Storyboard>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Text" Storyboard.TargetName="textBlock">
            <DiscreteObjectKeyFrame KeyTime="0" Value="Here is my text.nThis is new line"/>
    </Storyboard>
</VisualState>

输出文本为: Here is my text.nThis is new line
不带换行符。

注::如果这个值可以用资源文件中的字符串填充,那将是一个伟大的…!!这两种方法都对我有帮助,但后面一种是很好的方法。

当然…

Value="Here is my text.&#10;This is new line"

这行得通:

<TextBlock FontSize="20">
    <TextBlock.Resources>
        <Storyboard x:Name="MyStory">
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyLine1"
                    Storyboard.TargetProperty="Text">
                <DiscreteObjectKeyFrame KeyTime="0" Value="New Line 1" />
            </ObjectAnimationUsingKeyFrames>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyLine2" 
                    Storyboard.TargetProperty="Text">
                <DiscreteObjectKeyFrame KeyTime="0" Value="New Line 2" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </TextBlock.Resources>
    <TextBlock.Inlines>
        <Run x:Name="MyLine1" Text="Original Line 1" />
        <LineBreak />
        <Run x:Name="MyLine2" Text="Original Line 2" />
    </TextBlock.Inlines>
</TextBlock>

您也可以尝试这样做,而不使用LineBreak

<DiscreteObjectKeyFrame KeyTime="0" Value="New Line 1&#x0a;" />

最新更新