How to set text including new line character in storyboard

喜你入骨 提交于 2019-12-11 18:47:59

问题


Want to replace "\n" with new line character

<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>

The output text is: Here is my text.\nThis is new line
without new line character.

P.S.: If this value can be filled with the string in resource file that would be a great..!! Either way will help me out but later one is good approach.


回答1:


Sure thing...

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

Hope this helps.




回答2:


This works:

<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>

You could also try something like this without the LineBreak.

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


来源:https://stackoverflow.com/questions/14343376/how-to-set-text-including-new-line-character-in-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!