• 回到顶部按钮


     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;
                            }
                            else if (viewer_hot.VerticalOffset > 1)
                            {
                                imgTopBack.Visibility = System.Windows.Visibility.Visible;
                            }
                        };
                    }
                }
    
                #endregion
    }
      VisualStateGroup FindVisualState(FrameworkElement element, string name)
            {
                if (element == null) return null;
                IList groups = VisualStateManager.GetVisualStateGroups(element);
                foreach (VisualStateGroup group in groups)
                    if (group.Name == name) return group;
                return null;
            }
     private void imgTopBack_Tap(object sender, System.Windows.Input.GestureEventArgs e)
            {
                viewer_hot.ScrollToVerticalOffset(0.0);
                imgTopBack.Visibility = Visibility.Collapsed;
    
                e.Handled = true;
            }

    xaml 中:

     <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" />
  • 相关阅读:
    Dijkstra-leetcode 743.网络延迟时间
    BFS-leetcode787 K站中转内最便宜的航班
    图论基础——单源最短路径问题
    DFS leetcode-547 朋友圈
    SpringBoot 使用注解向容器中注册Bean的方法总结
    SpringBoot对SpringMVC的支持
    数据源简介
    Spring MVC简介
    2020-2-10 Python 列表切片陷阱:引用、复制与深复制
    2020-2-2 语法糖
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2475575.html
Copyright © 2020-2023  润新知