zoukankan      html  css  js  c++  java
  • 在ItemsControl 中,添加头部下拉更新

     <ScrollViewer x:Name="viewer_hot">
                            <Grid Margin="0,-60,0,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="60"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Border CornerRadius="10">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="White" Offset="0.217"/>
                                            <GradientStop Color="#FFC3FBEF" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                    <Grid x:Name="grid">
                                        <TextBlock x:Name="txtRefresh" Text="下拉更新" Margin="219,8,133,0" Foreground="Black" FontSize="16" Height="22" VerticalAlignment="Top"/>
                                        <Image x:Name="image" Source="images/insect.png" Width="32" Height="32" HorizontalAlignment="Left" Margin="134,13,0,15" d:LayoutOverrides="Width" RenderTransformOrigin="0.5,0.5" >
                                            <Image.RenderTransform>
                                                <CompositeTransform/>
                                            </Image.RenderTransform>
                                        </Image>
                                        <TextBlock Height="22" Margin="194,0,194,4" TextWrapping="Wrap" Text="最近更新:" VerticalAlignment="Bottom" Foreground="Black" FontSize="14.667"/>
                                        <TextBlock HorizontalAlignment="Right" Height="22" Margin="0,0,133,4" TextWrapping="Wrap" Text="5分钟前" VerticalAlignment="Bottom" Width="57" Foreground="Black" FontSize="14.667"/>
                                    </Grid>
                                </Border>
                                <ItemsControl  x:Name="listBox_Hot" Grid.Row="1"
                                 Width="468" 
                                 Margin="0,0,-12,-8"
                            ItemTemplate="{StaticResource ItemTemplate}" 
                                 ItemsSource="{Binding Collection, Source={StaticResource SampleDataSource}}"
                                 d:DataContext="{d:DesignData /SampleData/MainViewModelSampleData.xaml}">
                                </ItemsControl>
                            </Grid>
                        </ScrollViewer>
      //加载更新时播放的动画
                InsectTopSB.Completed += new EventHandler(InsectTopSB_Completed);
                InsectDownSB.Completed += new EventHandler(InsectDownSB_Completed);

    codeBehind 页面:

      #region 下拉更新
            private double actuableOffset, validStartOffset;
            private bool mplStarted;
            bool IsStoBorOn = false; //当前更新动画是否在播放
            protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
            {
                base.OnManipulationStarted(e);
                mplStarted = true;
            }
            protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
            {
                //actuableOffset = 0;
                validStartOffset = 0;
                mplStarted = false;
                //pivot.Title = "actuableOffset" + actuableOffset;
    
                base.OnManipulationCompleted(e);
            }
            protected override void OnMouseMove(MouseEventArgs e)
            {
                if (pivot.SelectedIndex == 0)  //只有选中第一个时触发
                {
                    //pivot.Title = "actuableOffset" + actuableOffset + "; VerticalOffset:" + viewer_hot.VerticalOffset;
                    if (!IsStoBorOn && actuableOffset >= 100)  //&& viewer_hot.VerticalOffset == 0
                    {
                        IsStoBorOn = true;
                        txtRefresh.Text = "正在更新...";
                        InsectTopSB.Begin();
                    }
    
                    if (!IsStoBorOn && actuableOffset < 100)
                    {
                        IsTabStop = true;
                        txtRefresh.Text = "下拉更新";
                        InsectDownSB.Begin();
                    }
    
                    if (viewer_hot.VerticalOffset <= 20)
                    {
                        if (mplStarted)
                        {
                            mplStarted = false;
                            validStartOffset = e.GetPosition(null).Y;
                        }
                        actuableOffset = e.GetPosition(null).Y - validStartOffset;
                    }
                }
                base.OnMouseMove(e);
            }
            void InsectDownSB_Completed(object sender, EventArgs e)
            {
                IsStoBorOn = false;
            }
    
            void InsectTopSB_Completed(object sender, EventArgs e)
            {
                IsStoBorOn = false;
            }
    
            #endregion
  • 相关阅读:
    大型网站架构演化发展历程
    用Haproxy给MySQL做负载均衡
    一致性hash和虚拟节点
    Apache + Tomcat +mod_jk 实现集群
    浅谈时钟的生成(js手写代码)
    javascript
    vue-cli中安装方法
    webstorm激活
    解决webstorm卡顿问题
    gulp前端自动化环境搭建详解
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2475571.html
Copyright © 2011-2022 走看看