WPF Textblock, linebreak in Text attribute

后端 未结 15 1205
南方客
南方客 2021-02-03 16:37

Is there a way to have \\n make a line break in a TextBlock?


Or is there a

相关标签:
15条回答
  • 2021-02-03 16:55

    How about breaking the line into two tags?

    <StackPanel>
        <TextBlock Text="Line1" />
        <TextBlock Text="Line2" />
    </StackPanel>
    
    0 讨论(0)
  • 2021-02-03 16:55

    Correct way to use it may be the following :

    <TextBlock>  
        <Span>text1</Span>  
        <LineBreak/>  
        <Span>text2</Span>  
    </TextBlock>
    
    0 讨论(0)
  • 2021-02-03 16:55

    I was having a similar problem and wanted to bind a String of xaml markup to a TextBlock. Essentialy storing the declarative markup inside a TextBlock in a string for later use.

    This is how I did: I subclassed the TextBlock to make the InlineCollection bindable and wrote a Converter between the string and an InlineCollection(or actually a generic list of Inlines.)

    0 讨论(0)
  • 2021-02-03 16:58

    The easiest way is

    <TextBlock> blabla <LineBreak /> coucou <LineBreak /> coucou 2 </TextBlock>

    So you just write XAML code, and the <LineBreak /> has exactly the same meaning the
    in HTML or the "\n" in C#.

    0 讨论(0)
  • 2021-02-03 16:59

    <LineBreak/>

    http://www.longhorncorner.com/UploadFile/mahesh/XamlLineBreak06092005152257PM/XamlLineBreak.aspx

    0 讨论(0)
  • 2021-02-03 16:59

    This also works fine:

    <TextBlock>
        <Run Text="My nice text"/>
        <LineBreak/>
        <LineBreak/>
        <Run Text="After some linebreaks, I'm back!"/>
    </TextBlock>
    
    0 讨论(0)
提交回复
热议问题