如何在文本块中输入?

时间:2015-09-05 09:25:44

标签: xml wpf

也许标题有点“误导”,为此我道歉。但是我想理解为什么当按下回车键时我的TextBlock没有换行,这是一个控制问题?也许它效果不好?这是我的xaml代码:

<Window x:Class="SF_DebugProject.Information"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Info" Height="400" Width="500">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid Grid.Column="0" Grid.Row="0">
        <Label>dfdfdfd dfdfd</Label>
    </Grid>

    <Grid Grid.Column="0" Grid.Row="2">
        <Label>
        <TextBlock TextWrapping="WrapWithOverflow">
            dfdfd diofsidi sdjoif
            dfd this should be wrap...
        </TextBlock>
        </Label>
    </Grid>
</Grid>

这是我告诉你的预览:

enter image description here

正如您所看到的那样,文本块的第二行不会换行,但会在第一行停止。从什么导致这个?

1 个答案:

答案 0 :(得分:1)

TextBlock中手动包装文本时,您几乎没有选择。您可以使用LineBreak

<TextBlock TextWrapping="WrapWithOverflow">
    dfdfd diofsidi sdjoif
    <LineBreak/>
    dfd this should be wrap...
</TextBlock>

或针对TextBlock设置xml:space="preserve",但这也会在每行之前保留空格

<TextBlock TextWrapping="WrapWithOverflow" xml:space="preserve">
    dfdfd diofsidi sdjoif
    dfd this should be wrap...
</TextBlock>

第三个选项是在Text

中添加换行符
<TextBlock 
    TextWrapping="WrapWithOverflow" 
    Text="dfdfd diofsidi sdjoif&#10;dfd this should be wrap..."/>
相关问题