0

我正在使用 silverlight4 当我从其他 Silverlight 页面导航到此页面时,我已经开发了一个页面,位置位于页面底部。我需要将焦点设置在 silverlight 页面的顶部。我没有在我的页面上使用 ScrollViewer .

4

1 回答 1

1

打开 MainPage.xaml 文件并将代码替换为以下内容。

    <UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="ScrollViewerControl.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
        <ScrollViewer Height="300" Width="300" Name="scrollViewer1"
                    VerticalScrollBarVisibility="Auto"
                    HorizontalScrollBarVisibility="Auto">
            <ScrollViewer.Content>
                <StackPanel>
                  ' Content Here
                </StackPanel>
            </ScrollViewer.Content>            
        </ScrollViewer>
    </Grid>   
</UserControl>

将 ScollViewer 偏移设置为零,如

scrollViewer1.ScrollToVerticalOffset(0); 

那么您的垂直滚动将始终位于顶部。

于 2013-10-07T10:34:09.810 回答