• 在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
  • 相关阅读:
    详解objc_msgSend
    shell变量类型
    web ssh vnc备忘录
    内存对齐
    vim ctags
    vim csupport 代码 快捷键
    程序在内存中的地址映射
    nginx+php配置
    tmux 复制
    sqlite insert select 联合使用
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2475571.html
Copyright © 2020-2023  润新知