我在Windows Phone 7頁面的內容面板網格周圍實現了ScrollViewer。但是,每當我嘗試向下滾動到頁面底部時,只要我將手指從屏幕上移開,它就會立即回到原始位置。換句話說,滾動它並不保留它的最後位置,使滾動毫無意義。如何阻止頁面回彈到原始位置
這是我的網頁代碼:
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71" x:Class="StepsForWater.Views.Submit"
mc:Ignorable="d"
d:DesignWidth="480"
d:DesignHeight="696"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
shell:SystemTray.IsVisible="True"
DataContext="{Binding Submit, Source={StaticResource Locator}}">
<!-- Sample code showing usage of ApplicationBar -->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton x:Name="appbar_About" IconUri="/Images/appbar_button1.png" Text="About" Click="appbar_About_Click"/>
<shell:ApplicationBarIconButton x:Name="appbar_WalkRun" IconUri="/Images/appbar_button2.png" Text="Walk/Run" Click="appbar_WalkRun_Click"/>
<!--<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem x:Name="menuItem1" Text="MenuItem 1"></shell:ApplicationBarMenuItem>
<shell:ApplicationBarMenuItem x:Name="menuItem2" Text="MenuItem 2"></shell:ApplicationBarMenuItem>
</shell:ApplicationBar.MenuItems>-->
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="/StepsForWater;component/Images/submit-bg.png" />
</Grid.Background>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel"
Grid.Row="0"
Margin="12,17,0,28">
<!--<TextBlock x:Name="ApplicationTitle"
Text="MY APPLICATION"
Style="{StaticResource PhoneTextNormalStyle}" />
<TextBlock x:Name="PageTitle"
Text="page name"
Margin="9,-7,0,0"
Style="{StaticResource PhoneTextTitle1Style}" />-->
</StackPanel>
<ScrollViewer>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,-241" Background="{x:Null}">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,57,0,0" x:Name="tBlk_Username" Text="{Binding UserName}" VerticalAlignment="Top" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="27,79,0,0" x:Name="tb_UserNameVal" Text="{Binding UserNameValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,169,0,0" x:Name="tBlk_Email" Text="{Binding Email}" VerticalAlignment="Top" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="38,278,0,0" x:Name="tBlk_Message" Text="{Binding Message}" VerticalAlignment="Top" />
<TextBox Height="72" HorizontalAlignment="Left" Margin="27,191,0,0" x:Name="tb_EmailVal" Text="{Binding EmailValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<TextBox Height="153" HorizontalAlignment="Left" Margin="27,300,0,0" x:Name="tb_MessageVal" Text="{Binding MessageValue, Mode=TwoWay}" VerticalAlignment="Top" Width="423" />
<CheckBox Content="{Binding Location}" Height="72" HorizontalAlignment="Left" Margin="27,459,0,0" x:Name="chk_Location" VerticalAlignment="Top" />
<Button Content="{Binding Submit}" Height="72" HorizontalAlignment="Left" Margin="27,761,0,0" x:Name="btn_Submit" VerticalAlignment="Top" Width="160" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="SubmitClick" Command="{Binding SubmitCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBlock Height="30" HorizontalAlignment="Left" Margin="50,540,0,0" Name="tBlk_PicInfo" Text="{Binding PictureInfo}" VerticalAlignment="Top" Grid.Row="1" />
<Image Height="150" HorizontalAlignment="Left" Margin="50,583,0,0" Name="img_FlickrPic" Stretch="Fill" VerticalAlignment="Top" Width="200" Grid.Row="1" Source="{Binding ImageSource}"/>
<Button Content="Capture" Height="72" HorizontalAlignment="Left" Margin="267,0,0,138" Name="btn_Capture" VerticalAlignment="Bottom" Width="160" d:LayoutOverrides="GridBox" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="CaptureClick" Command="{Binding CaptureCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
</ScrollViewer>
</Grid>
更新:修正了我的問題,所有我需要做的就是確保我的ScrollViewer的高度比它更低真實含有格!
什麼是所有的高度和利潤率?你應該使用具有行/列定義/ StackPanels的網格。我不認爲有任何事情的餘地是個好主意。 – 2012-02-14 19:41:50
可怕的佈局風格! – MyKuLLSKI 2012-02-14 20:01:03
我並沒有真正關注佈局,我所做的所有事情都是在OOTB模板中可用的內容面板網格內的設計表面上引發控件。所有這些格式都是基於我將這些控件放置在另一個之下而生成的代碼。顯然,設計者只是產生可怕的代碼:)。除了添加ScrollViewer之外,我還沒有手動觸摸過xaml。這真是一款沙盒應用程序。 – Cranialsurge 2012-02-15 00:01:33