回到顶部按钮
<p>asp.net 实现回到顶部的按钮效果</p><pre>void MainPage_Loaded(object sender, RoutedEventArgs e) { #region 回到顶部按钮 // Visual States are always on the first child of the control template FrameworkElement element = VisualTreeHelper.GetChild(viewer_hot, 0) as FrameworkElement; if (element != null) { VisualStateGroup group = FindVisualState(element, "ScrollStates"); if (group != null) { //group.CurrentStateChanging += (s, args) => pivot.Title = args.NewState.Name; group.CurrentStateChanging += (s, args) => { if (args.NewState.Name == "Scrolling") { imgTopBack.Visibility = System.Windows.Visibility.Collapsed; } elseif (viewer_hot.VerticalOffset > 1) { imgTopBack.Visibility = System.Windows.Visibility.Visible; } }; } } #endregion }</pre><div style="page-break-after: always;"><span style="display: none;"><!--more-->& nbsp ;</span></div><div> <pre> VisualStateGroup FindVisualState(FrameworkElement element, string name) { if (element == null) returnnull; IList groups = VisualStateManager.GetVisualStateGroups(element); foreach (VisualStateGroup group in groups) if (group.Name == name) return group; returnnull; }</pre><div> </div></div><div><pre>privatevoid imgTopBack_Tap(object sender, System.Windows.Input.GestureEventArgs e) { viewer_hot.ScrollToVerticalOffset(0.0); imgTopBack.Visibility = Visibility.Collapsed; e.Handled = true; }</pre><div> </div></div><p>xaml 中:</p><div><pre> <Image Height="56" Width="56" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="12,0,0,80" Name="imgTopBack" Source="/images/topBack.png" Stretch="Fill" Visibility="Collapsed" Tap="imgTopBack_Tap" /></pre></div>