WPF Layout: перенос слов не работает - PullRequest
1 голос
/ 26 января 2009

Почему текст в моем 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>

1 Ответ

3 голосов
/ 26 января 2009

Он внутри Canvas, поэтому он не получает никакой ширины. Если вам не нужен холст, измените его на сетку (которая автоматически изменяет размеры), и TextBlock будет правильно переноситься.

...