Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF布局:字换行不工作_Wpf_Layout_Textblock - Fatal编程技术网

WPF布局:字换行不工作

WPF布局:字换行不工作,wpf,layout,textblock,Wpf,Layout,Textblock,为什么即使我指定了换行符,TextBlock中的文本仍会向右延伸到画布之外 <Window x:Class="WpfApplication6.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" SizeToContent="Wid

为什么即使我指定了换行符,TextBlock中的文本仍会向右延伸到画布之外

<Window x:Class="WpfApplication6.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" SizeToContent="WidthAndHeight">
    <DockPanel>
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
            <Button Content="111"/>
            <Button Content="222"/>
            <Button Content="333"/>
            <Button Content="444"/>
            <Button Content="555"/>
        </StackPanel>
        <StackPanel DockPanel.Dock="Left">
            <Button Content="One"/>
            <Button Content="Two"/>
            <Button Content="Three"/>
            <Button Content="Four"/>
            <Button Content="Five"/>
        </StackPanel>
        <Canvas Background="tan">
            <TextBlock TextWrapping="Wrap">This is the content in this area here</TextBlock>
        </Canvas>
    </DockPanel>
</Window>

这是本区域的内容
解决方案:谢谢你,史蒂夫,成功了,我还添加了一个ScrollViewer,很好:

<DockPanel>
    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
        <Button Content="111"/>
        <Button Content="222"/>
        <Button Content="333"/>
        <Button Content="444"/>
        <Button Content="555"/>
    </StackPanel>
    <StackPanel DockPanel.Dock="Left">
        <Button Content="One" Click="Button_Click" />
        <Button Content="Two"/>
        <Button Content="Three"/>
        <Button Content="Four"/>
        <Button Content="Five"/>
    </StackPanel>
    <Grid Background="tan">
        <ScrollViewer>
            <TextBlock Name="mainArea" Padding="10" TextWrapping="Wrap">This is the content in this area here</TextBlock>
        </ScrollViewer>
    </Grid>
</DockPanel>

这是本区域的内容

它位于画布内,因此没有设置任何宽度。如果不需要画布,请将其更改为网格(自动调整大小),TextBlock将正确包装