2013-11-27 57 views
1

我有一個基於Panorama控件的應用程序。點擊全景圖控件的頁面(標籤)之一上的項目轉到詳細信息頁面。在該詳細信息頁面上,我有下面的XAML呈現項目內容。如您所見,TextBlockStackPanel託管在手機中:PanoramaItem.Header元素。我想要那個元素中的文字換行視頻標題TextBlock綁定在視圖模型中。我有TextWrapping設置爲換行,我已經指定它的固定寬度,所以TextBlock不增長/擴大(因此將不會換行)。文字沒有換行,但有些線條仍然出現剪輯,出現一些詞語「切斷」。我的XAML有什麼問題?Windows Phone 8 - StackPanel中的TextBlock沒有正確包裝文本?

我讀到使用DockPanel中代替:

TextBlock Wrapping in WPF Layout

但這個程序有一個的StackPanel上有很多不同的頁面中使用,所以如果我可以用的StackPanel我」大棒d更喜歡它。

<Grid x:Name="LayoutRoot"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid Grid.Row="0" Visibility="{Binding IsInternetAvailable}" Background="{StaticResource PhoneAccentBrush}" Height="30"> 
     <TextBlock Text="{Binding Path=LocalizedResources.NoConnection, Source={StaticResource LocalizedStrings}}" Margin="10, 0"/> 
    </Grid> 
    <phone:Panorama x:Name="PanoramaFavorites_DetailVideos" Grid.Row="2" Foreground="{StaticResource CustomApplicationTextBrush}" Background="{StaticResource CustomApplicationBackgroundImage}" SelectionChanged="panoramaFavorites_DetailVideos_SelectionChanged"> 
     <phone:Panorama.Title> 
      <StackPanel Orientation="Horizontal" Margin="0,15,0,0"> 
       <Image Height="85" Width="85" Source="http://appstudiodata.blob.core.windows.net/apps/1383/db936107-bce6-41a2-9d95-1d342f66c6bb/res/Logo-b3883645-a6cd-4cc8-82be-97c87a266656.png" Stretch="Uniform" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="5,0,10,5" RenderTransformOrigin="0.5,0.5" /> 
       <TextBlock FontSize="92" Text="Robot Videos" FontFamily="Segoe WP Light" Foreground="{StaticResource CustomTitleApplicationTextBrush}" VerticalAlignment="Stretch"/> 
      </StackPanel> 
     </phone:Panorama.Title> 
     <phone:PanoramaItem x:Name="PanoramaFavorites_DetailVideos0" Margin="0,0,0,25"> 
      <phone:PanoramaItem.Header> 
       <StackPanel Orientation="Horizontal" Margin="0,7,0,0"> 
        <TextBlock Text="{Binding CurrentYouTubeVideo.Title, Converter={StaticResource SanitizeString}}" Foreground="{StaticResource CustomApplicationTextBrush}" FontSize="36" TextWrapping="Wrap" Width="440" Height="170"/> 
       </StackPanel> 
      </phone:PanoramaItem.Header> 
      <ctl:FlipControl NextElementCommand="{Binding NextpanoramaFavorites_DetailVideos0}" PreviousElementCommand="{Binding PreviouspanoramaFavorites_DetailVideos0}" ShowPreviousButton="{Binding HasPreviouspanoramaFavorites_DetailVideos0}" ShowNextButton="{Binding HasNextpanoramaFavorites_DetailVideos0}"> 
       <ctl:FlipControl.InnerContent> 
      <Grid Margin="10,5,5,5">  
       <ScrollViewer> 
         <ctl:YouTubePlayer Margin="0,10" MaxHeight="250" VerticalAlignment="Top" VideoId="{Binding CurrentYouTubeVideo.VideoId, TargetNullValue={StaticResource DefaultNoImageValue}}"/> 
       </ScrollViewer> 
      </Grid> 
       </ctl:FlipControl.InnerContent> 
      </ctl:FlipControl> 
     </phone:PanoramaItem> 
    </phone:Panorama> 
</Grid> 
+1

你指定的確切大小將是,那麼你怎麼能指望當你有太多的文字,以適應它的行爲在你給它的空間? – steveg89

+0

@ steveg89我希望它可以使用分詞符將文本換行到下一行,以便在單詞超過TextBlock的指定寬度時決定在哪裏進行換行。 –

回答

6

根據您的意見,這對我的作品:

<StackPanel Orientation="Vertical" Margin="0,7,0,0"> 
    <TextBlock Text="{Binding CurrentYouTubeVideo.Title, Converter={StaticResource SanitizeString}}" 
       Foreground="{StaticResource CustomApplicationTextBrush}" 
       FontSize="36" 
       TextWrapping="Wrap" 
       MaxWidth="440"/> 
</StackPanel>