2014-03-07 61 views
0

我正在從一些Microsoft Sample Code工作,它似乎有一個ScrollViewer它似乎沒有按預期工作(或我期望和希望它)。Windows Store應用嵌入ScrollViewer無法正常工作

<common:LayoutAwarePage 
x:Class="ControlChannelHttpClient.Scenario1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:ControlChannelHttpClient" 
xmlns:common="using:SDKTemplate.Common" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 

<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" VerticalAlignment="Top"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Grid x:Name="Input" Grid.Row="0"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
     <StackPanel Margin="0"> 
      <TextBlock TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}"> 
      This scenario demonstrates how to use the ControlChannelTrigger object with HttpClient. 
      This app demonstrates an HTTP client. A server is provided with this sample. 
      The client and server must be deployed on separate machines. Once the server is set up, 
      the client can set up the ControlChannelTrigger with the HttpClient by clicking Connect. 
      This sends an HTTP request to the server. Note that the server by default responds by completing the 
      HTTP request after a delay of 25 seconds. This delay is to ensure the client app can have enough time 
      to enter suspended state and then receive the incoming HTTP response from the server. 
      </TextBlock> 
      <Grid x:Name="ClientSettings" Margin="5"> 
       <Grid.RowDefinitions> 
        <RowDefinition/> 
        <RowDefinition/> 
        <RowDefinition/> 
       </Grid.RowDefinitions> 
       <TextBlock Grid.Row="0" Text="Server Name: " TextWrapping="Wrap" VerticalAlignment="Center" Style="{StaticResource BasicTextStyle}" /> 
       <TextBox Grid.Row="1" Grid.ColumnSpan="2" x:Name="ServerUri" Text="http://Server-HostName/CCTHttpServerSample/default.aspx" HorizontalAlignment="Left" VerticalAlignment="Center" /> 
       <StackPanel Orientation="Horizontal" Grid.Row="2"> 
        <Button x:Name="ConnectButton" Content="Connect" Click="ConnectButton_Click" /> 
        <Button x:Name="ClearButton" Content="Clear Log" Click="ClearButton_Click" /> 
       </StackPanel> 
      </Grid> 
     </StackPanel> 
     <!-- Add Storyboards to the visual states below as necessary for supporting the various layouts for the input section --> 
     <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup> 
       <VisualState x:Name="InputDefaultLayout"/> 
       <VisualState x:Name="InputBelow768Layout"/> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
    </Grid> 

    <Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1"> 
     <ScrollViewer 
     HorizontalScrollBarVisibility="Disabled" 
     VerticalScrollBarVisibility="Auto" 
     HorizontalScrollMode="Disabled" 
     VerticalScrollMode="Enabled" 
     ZoomMode="Disabled" 
     Margin="10,4,10,0"> 
      <TextBlock x:Name="DebugTextBlock" 
        TextWrapping="Wrap" 
        Style="{StaticResource BasicTextStyle}" 
        IsTextSelectionEnabled="True" /> 
     </ScrollViewer> 
     <!-- Add Storyboards to the visual states below as necessary for supporting the various layouts for the output section --> 
     <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup> 
       <VisualState x:Name="OutputDefaultLayout"/> 
       <VisualState x:Name="OutputBelow768Layout"/> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
    </Grid> 
</Grid> 

我期望ScrolViewer底部(並希望它)把TextBlock圍繞滾動條的,當它需要它。

該示例在TextBlock中顯示調試,但填充後,整個佈局變得可滾動,而不僅僅是TextBlock

你能告訴我爲什麼嗎?我需要做什麼才能使滾動條僅出現在TextBlock的周圍?

回答

0

只需要一個高度。 Height="200"

<ScrollViewer 
    HorizontalScrollBarVisibility="Disabled" 
    VerticalScrollBarVisibility="Auto" 
    HorizontalScrollMode="Disabled" 
    VerticalScrollMode="Enabled" 
    ZoomMode="Disabled" 
    Margin="10,4,10,0"> 
     <TextBlock x:Name="DebugTextBlock" 
       TextWrapping="Wrap" 
       Style="{StaticResource BasicTextStyle}" 
       IsTextSelectionEnabled="True" Height="200"/> 
    </ScrollViewer> 
    <!-- Add Storyboards to the visual states below as necessary for supporting the various layouts for the output section --> 
    <VisualStateManager.VisualStateGroups> 
     <VisualStateGroup> 
      <VisualState x:Name="OutputDefaultLayout"/> 
      <VisualState x:Name="OutputBelow768Layout"/> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 
</Grid> 

這沒有原來工作的原因,是由於具有ScrollViewer父佈局,使得嵌套在這個滾動視圖。