2012-03-09 68 views

回答

0

我創建了一個解決這個問題。通過測量文本,您可以手動拆分的文字兩個部分組成>

<Grid Width="400"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto" /> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <Image x:Name="WrapContent" Width="200" Height="192" /> 
    <TextBlock x:Name="RightTextBlock" Width="200" FontSize="24" FontFamily="Segoe WP" TextWrapping="Wrap" Grid.Column="1" /> 
    <TextBlock x:Name="BottomTextBlock" Width="400" FontSize="24" FontFamily="Segoe WP" TextWrapping="Wrap" Grid.Row="1" Grid.ColumnSpan="2" /> 
</Grid> 

public MainPage() 
{ 
    InitializeComponent(); 

    string text = "Lorem ipsum dolor sit amet consectetur adipiscing elit. Lorem ipsum dolor sit amet consectetur adipiscing elit. Lorem ipsum dolor sit amet consectetur adipiscing elit. Lorem ipsum dolor sit amet consectetur adipiscing elit. Lorem ipsum dolor sit amet consectetur adipiscing elit. Lorem ipsum dolor sit amet consectetur adipiscing elit."; 
    string[] words = text.Split(' '); 
    RightTextBlock.Text = words[0]; 

    for (int i = 0; i < words.Length; i++) 
    { 
     string word = words[i]; 
     string previousText = RightTextBlock.Text; 
     RightTextBlock.Text += " " + word; 
     if (RightTextBlock.ActualHeight > WrapContent.ActualHeight) 
     { 
      RightTextBlock.Text = previousText; 
      BottomTextBlock.Text += String.Join(" ", words.Skip(i)); 
      break; 
     } 
    } 
} 
相關問題