Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF inkcanvas多点触摸?_C#_Wpf_Multi Touch_Inkcanvas - Fatal编程技术网

C# WPF inkcanvas多点触摸?

C# WPF inkcanvas多点触摸?,c#,wpf,multi-touch,inkcanvas,C#,Wpf,Multi Touch,Inkcanvas,我正在为触摸屏创建一个简单的绘画应用程序,我一直在为在inkcanvas中缩放和旋转而使用多点触摸手势,但我还没有找到解决方案 在inkcanvas中是否有提供多点触控手势的简单方法?使用系统; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System

我正在为触摸屏创建一个简单的绘画应用程序,我一直在为在inkcanvas中缩放和旋转而使用多点触摸手势,但我还没有找到解决方案

在inkcanvas中是否有提供多点触控手势的简单方法?

使用系统;
    using System;
    using System.Collections.Generic;
    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>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            Dictionary<int, System.Windows.Ink.Stroke> myStrokes;
            public MainWindow()
            {
                InitializeComponent();
                myStrokes = new Dictionary<int, System.Windows.Ink.Stroke>();
                this.WindowState = System.Windows.WindowState.Maximized;
                SandyCanvas.TouchDown += SandyCanvas_OnTouchDown;
                SandyCanvas.TouchUp += SandyCanvas_OnTouchUp;
                SandyCanvas.TouchMove += SandyCanvas_OnTouchMove;
            }
            private void SandyCanvas_OnTouchMove(object sender, TouchEventArgs e)
            {
                var touchPoint = e.GetTouchPoint(this);
                var point = touchPoint.Position;

                if (myStrokes.ContainsKey(touchPoint.TouchDevice.Id))
                {
                    var stroke = myStrokes[touchPoint.TouchDevice.Id];
                    var nearbyPoint = CheckPointNearby(stroke, point);
                    if (!nearbyPoint)
                    {
                        stroke.StylusPoints.Add(new StylusPoint(point.X, point.Y));
                    }
                }
            }
            private static bool CheckPointNearby(System.Windows.Ink.Stroke stroke, Point point)
            {
                return stroke.StylusPoints.Any(p => (Math.Abs(p.X - point.X) <= 1) && (Math.Abs(p.Y - point.Y) <= 1));                
            }
            private void SandyCanvas_OnTouchUp(object sender, TouchEventArgs e)
            {
                var touchPoint = e.GetTouchPoint(this);
                myStrokes.Remove(touchPoint.TouchDevice.Id);
            }        
            private void SandyCanvas_OnTouchDown(object sender, TouchEventArgs e)
            {
                var touchPoint = e.GetTouchPoint(this);
                var point = touchPoint.Position;
                System.Windows.Ink.Stroke newStroke = new System.Windows.Ink.Stroke(new StylusPointCollection(new List<Point> { point }), SandyCanvas.DefaultDrawingAttributes);
                if (!myStrokes.ContainsKey(touchPoint.TouchDevice.Id))
                {
                    myStrokes.Add(touchPoint.TouchDevice.Id, newStroke);
                    SandyCanvas.Strokes.Add(newStroke);
                }
            }
        }
    }

/////////////////////Designer Page////////////////////
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <InkCanvas x:Name="SandyCanvas"></InkCanvas>
    </Grid>
</Window>
使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Threading.Tasks; 使用System.Windows; 使用System.Windows.Controls; 使用System.Windows.Data; 使用System.Windows.Documents; 使用System.Windows.Input; 使用System.Windows.Media; 使用System.Windows.Media.Imaging; 使用System.Windows.Navigation; 使用System.Windows.Shapes; 命名空间WpfApplication1 { /// ///MainWindow.xaml的交互逻辑 /// 公共部分类主窗口:窗口 { 字典迷思; 公共主窗口() { 初始化组件(); myStrokes=新字典(); this.WindowState=System.Windows.WindowState.Maximized; SandyCanvas.TouchDown+=SandyCanvas_OnTouchDown; SandyCanvas.TouchUp+=SandyCanvas_OnTouchUp; SandyCanvas.TouchMove+=SandyCanvas_OnTouchMove; } 私有void SandyCanvas_OnTouchMove(对象发送方,TouchEventArgs e) { var-touchPoint=e.GetTouchPoint(this); var点=接触点位置; if(myStrokes.ContainsKey(touchPoint.TouchDevice.Id)) { var stroke=myStrokes[touchPoint.TouchDevice.Id]; var nearbyPoint=检查点附近(笔划,点); 如果(!nearbyPoint) { stroke.StylusPoints.Add(新StylusPoint(point.X,point.Y)); } } } 私有静态布尔检查点(System.Windows.Ink.Stroke-Stroke,Point-Point) {
return stroke.StylusPoints.Any(p=>(Math.Abs(p.X-point.X))Surface 2.0 SDK库中有一个。但是,在高于2010的Visual Studio中安装SDK有点棘手。也许它可以工作……我应该查找有关如何安装它的信息(我使用Visual Studio 2013)。它也与鼠标点击兼容吗?不确定,但它也应该与鼠标输入兼容。对于安装,您可能可以使用Orca之类的工具修补MSI。Surface SDK的一个主要缺点是,您还需要在目标系统上安装Surface运行时。哦…看起来有点混乱…我将寻找m更多信息,但我已经看到一些人能够轻松实现多点触摸,但这对我来说是一个混乱。虽然这段代码可能会回答这个问题,但提供了关于为什么和/或如何回答这个问题的额外上下文,提高了它的长期价值。这段代码适用于多点触摸环境。如果你在画布上绘制5个图形es然后5条线将同时绘制。这意味着可以实现多点触摸线。添加了designer和.cs代码。您可以在模拟器或多点触摸系统上检查并运行代码。只需给出在InkCanvas上实现多点触摸绘制的示例代码。如果您想在ink canvas上处理多点触摸手势,则需要手动处理…但如果要在墨水画布上使用单触式手势,必须设置编辑模式ie.InkCanvasEditingMode.InkAnd手势。