如何在故事板中设置包括换行符的文本

时间:2013-01-15 17:31:37

标签: windows-8 winrt-xaml windows-store-apps

想要用新行字符替换“\ 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
没有新的线条特征。

P.S。:如果此值可以填充资源文件中的字符串,那将是一个很棒的.. !! 无论哪种方式都会帮助我,但后来一个方法很好。

2 个答案:

答案 0 :(得分:2)

当然......

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

希望这有帮助。

答案 1 :(得分:1)

这有效:

<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;" />