问题
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. 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
" />
来源:https://stackoverflow.com/questions/14343376/how-to-set-text-including-new-line-character-in-storyboard