2009-01-26 5 views
1

Pourquoi le texte de mon TextBlock s'étend-il vers la droite au-delà de ma toile même si j'ai spécifié un habillage de texte?Mise en page WPF: l'habillage de mots ne fonctionne pas

<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> 

SOLUTION: Merci, Steve, qui l'a fait, j'ai ajouté un ScrollViewer aussi bien, agréable:

<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> 

Répondre

3

Il est dans une toile, il est donc de ne pas obtenir un ensemble de largeur. Si vous n'avez pas besoin de la toile, remplacez-la par une grille (qui se redimensionne automatiquement) et le TextBlock s'enroulera correctement.

Questions connexes