0

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.

Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184

2 Answers2

2

Sure thing...

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

Hope this helps.

Chris W.
  • 22,835
  • 3
  • 60
  • 94
1

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;" />
Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233