zoukankan      html  css  js  c++  java
  • WPF图片列表触摸滑动

    实现动态加载图片列表,并能触摸滑动的效果,所以使用UniformGrid控件来显示列表,搭配surface的多点触摸来做滑动。

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:surface="http://schemas.microsoft.com/surface/2008"
            Title="MainWindow" Height="600" Width="800">
        <Grid>
            <surface:SurfaceScrollViewer x:Name="scrollViewer1" ScrollViewer.PanningMode="VerticalOnly" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                <UniformGrid VerticalAlignment="Top" Name="uniformGrid1" Columns="3"></UniformGrid>
            </surface:SurfaceScrollViewer>
        </Grid>
    </Window>

    如果在TouchUp或MouseUp是就出发查看图片详情,会在触摸滑动后也触发此事件,所以需要判断是否点击后弹起,这样就可以在图片的MouseUp事件里加入查看图片详情。

    后台代码:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            bool isMoving = false, isClick = false;
    
            public MainWindow()
            {
                InitializeComponent();
    
                for (int i = 0; i < 10; i++)
                {
                    StackPanel panel = new StackPanel();
                    panel.Width = 200;
                    panel.Height = 200;
                    panel.Margin = new Thickness(10);
                    panel.Background = Brushes.Black;
                    panel.PreviewMouseUp += new MouseButtonEventHandler((o, e) =>
                    {
                        if (!isMoving && isClick)
                        {
                            isClick = false;
                        }
                    });
                    panel.PreviewTouchDown += new EventHandler<TouchEventArgs>((o, e) =>
                    {
                        isClick = true;
                    });
                    uniformGrid1.Children.Add(panel);
                }
    
                scrollViewer1.PreviewTouchDown += new EventHandler<TouchEventArgs>((o, e) =>
                {
                    isMoving = false;
                    isClick = false;
                });
                scrollViewer1.PreviewTouchUp += new EventHandler<TouchEventArgs>((o, e) =>
                {
                    isMoving = false;
                });
                scrollViewer1.ScrollChanged += new ScrollChangedEventHandler((o, e) =>
                {
                    isMoving = true;
                    isClick = false;
                });
            }
        }
    }
    

    这本不该是问题的,但就是这样的小程序在公司的硬件设备上不能正常使用,原因是硬件对MouseUp与TouchUp支持不好。

  • 相关阅读:
    Smobiler如何实现.net一键开发,ios和android跨平台运行
    使用Smobiler实现类似美团的界面
    疫情当下,企业系统如何快速实现移动化?
    Smobiler针对百度文字识别SDK动态编译与运行
    smobiler自适应不同手机分辨率
    仓库管理移动应用解决方案——C#开发的移动应用开源解决方案
    移动OA办公——Smobiler第一个开源应用解决方案,快来get吧
    react-native 标题随页面滚动显示和隐藏
    react-native 键盘遮挡输入框
    解决adb网络连接中出现的“由于目标计算机积极拒绝,无法连接”错误
  • 原文地址:https://www.cnblogs.com/yutian130/p/3029618.html
Copyright © 2011-2022 走看看