2014-03-07 38 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父布局,使得嵌套在这个滚动视图。