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支持不好。

 

转载于:https://www.cnblogs.com/yutian130/archive/2013/04/18/3029618.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值