【问题标题】:Windows Store app embedded ScrollViewer not working properlyWindows 应用商店应用嵌入的 ScrollViewer 无法正常工作
【发布时间】:2014-03-08 00:26:18
【问题描述】:

我正在使用一些 Microsoft Sample Code 工作,其中似乎有一个 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 周围?

【问题讨论】:

    标签: c# wpf windows-store-apps scrollviewer


    【解决方案1】:

    只需要一个高度。 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,使此滚动视图嵌套。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多