2

我创建了一个页面,其中有很多来自用户的输入。所以用户应该能够向下滚动以便能够按下上传按钮。要在页面上向下滚动,我在网格外使用了 ScrollViewer。我可以滚动,但向下滚动后页面不断向后滚动。

这是我的代码:

  <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanelButtom" Grid.Row="1" >
            <ScrollViewer >
                <Grid x:Name="ContentPanel" Background="black">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="154" />
                        <ColumnDefinition Width="326" />
                    </Grid.ColumnDefinitions>
                    <Image Height="109" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="167" Margin="23,19,0,0" Source="{Binding Path=ImageSoruce, Mode=TwoWay}" Grid.ColumnSpan="2" />
                    <TextBox Height="71" HorizontalAlignment="Left" Margin="12,161,0,0" Name="nameInput" Text="{Binding Path=Name, Mode=TwoWay}" VerticalAlignment="Top" Width="430" Grid.ColumnSpan="2" />
                    <TextBlock Height="56" HorizontalAlignment="Left" Margin="23,134,0,0" Name="nameLabel" Text="Name" VerticalAlignment="Top" Width="130" FontSize="25" />
                    <TextBlock FontSize="25" Height="60" HorizontalAlignment="Left" Margin="23,238,0,0" Name="descriptionLabel" Text="Description" VerticalAlignment="Top" Width="130" />
                    <TextBox Height="72" HorizontalAlignment="Left" Margin="12,265,0,0" Name="descriptionInput" Text="{Binding Path=Description, Mode=TwoWay}" VerticalAlignment="Top" Width="430" IsEnabled="True" Grid.ColumnSpan="2" />
                    <TextBlock FontSize="25" Height="60" HorizontalAlignment="Left" Margin="23,343,0,0" Name="locationLabel" Text="Location" VerticalAlignment="Top" Width="130" />
                    <TextBlock Height="46" HorizontalAlignment="Left" Margin="24,384,0,0" Name="locationInput" Text="{Binding Path=Location, Mode=TwoWay}" VerticalAlignment="Top" Width="401" Loaded="locationInput_Loaded" Grid.ColumnSpan="2" />
                    <toolkit:ListPicker SelectionMode="Multiple" FullModeHeader="CATEFORIES" x:Name="ListPickerCategories" CacheMode="BitmapCache" HorizontalAlignment="Left" Margin="25,492,0,0" VerticalAlignment="Top" Width="401" Grid.ColumnSpan="2" ItemsSource="{Binding Categories}" Height="78"></toolkit:ListPicker>
                    <TextBlock FontSize="25" Height="60" HorizontalAlignment="Left" Margin="24,436,0,0" Name="textBlock1" Text="Categories" VerticalAlignment="Top" Width="130" />
                    <Button Content="Upload" Height="86" HorizontalAlignment="Left" Margin="26,604,0,0" Name="UploadButton" VerticalAlignment="Top" Width="411" Click="UploadButton_Click" Grid.ColumnSpan="2" />
                </Grid>
            </ScrollViewer>
            </Grid>

这个问题的原因可能是什么,我该如何解决?

4

2 回答 2

6

用于StackPanels将元素放在另一个之下。删除所有margins,heightwidth其他绝对定位的东西

<Grid x:Name="ContentPanelButtom" Grid.Row="1" >
    <ScrollViewer>
        <StackPanel>
            <!-- elements here -->
        </StackPanel>
    </ScrollViewer>
</Grid>
于 2012-04-13T09:03:10.397 回答
0

我遇到过同样的问题。但最后我解决了它,我只是使用 Height 属性来做到这一点。请执行以下步骤

  • 首先创建一个ScrollViewer
  • Indide ScrollViewer 创建一个容器(例如:Grid/StackPanel/Border 等...)并将每个控件放入其中。
  • 为 ScrollViewer 和 Container 设置固定的高度(注意:容器的高度应该大于 ScrollViewer 的高度)

请参阅下面的代码

<ScrollViewer Height="500">
        <Grid Name="Container" Height="700">
            <TextBox/>
            <TextBox/>
            <TextBox/>
        </Grid>
</ScrollViewer>

现在您可以滚动容器网格甚至显示的键盘,甚至可以将焦点放在文本框上。

于 2013-12-20T08:43:19.583 回答