来自给定鼠标坐标的MatrixTransformations的Matrix值 [英] MatrixTransformations' Matrix value from the Given Mouse Coordinates

查看:88
本文介绍了来自给定鼠标坐标的MatrixTransformations的Matrix值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发触摸应用程序" ,用户可以在其中从工具箱中拖放,放下后,可以在画布上移动它. (例如,从一个位置移动到另一位置(平移)并旋转它 等)

I am developing the "touch application", where the user can drag and drop from the tool box and after dropping, they can move it around the canvas. (like moving from one position to another position (Translation) and rotating it etc.)

对于拖放,我使用的是"Touch Down";和掉落"活动,为了移动它,我正在使用

For drag and drop, I am using "Touch Down" and "Drop" events, and for the moving it around, i am using 

操纵事件.

我使用的是Matrix Transformation,用于支持画布中的旋转和平移.

I am using Matrix Transformation, for supporting rotation, translation in the canvas. 

在拖放时,将仅从参数"e"获得鼠标坐标.在Drop Event处理程序中.

While dropping, will get only Mouse Coordinates from the parameter "e" in the Drop Event handlers.

但是我必须将鼠标坐标点转换为等效的Matrix值,然后才能将其绑定到确切的位置.

But I have to convert the mouse coordinate  points into the equivalent Matrix value, then only, I can able to bind it to the exact location.

注意:我没有使用Canvas.Left和Canvas.Right来显示项目.它正在执行Matrix变换,因此,如果我获得矩阵值,那么我可以轻松地做到这一点.

Note: I am not using Canvas.Left and Canvas.Right to display the items. It is having the Matrix transform, and so if i get the matrix value, then I can easily do it.

我已经在操纵事件的帮助下进行了拖放操作,但是我做不到!

I have searched to do the Drag and drop with the help of manipulation events, But I am unable to do!.

我使用的代码如下:-

<StackPanel IsManipulationEnabled="True"                                    Tag="{Binding}"  TouchDown="StackPanel_TouchDown" />


       <ItemsControl ItemsSource="{Binding DataContainer}" 
                      x:Name="MainDataContentHolder" >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas x:Name="canvMain" 
                            Drop="canvMain_Drop"  AllowDrop="True" >
                    </Canvas>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>

            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Image Loaded="TargetImage_Loaded"
                            Source="{Binding ImagePath}" Tag="{Binding}"
                           IsManipulationEnabled="True" 
                           StylusSystemGesture="TargetImage_StylusSystemGesture"
                               ManipulationInertiaStarting="TargetImage_ManipulationInertiaStarting"
                               ManipulationStarting="TargetImage_ManipulationStarting"
                               ManipulationDelta="TargetImage_ManipulationDelta">
                        <Image.RenderTransform>
                            <MatrixTransform x:Name="MatrixRotationTransform" />
                        </Image.RenderTransform>
                    </Image>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>


private void StackPanel_TouchDown(object sender, TouchEventArgs e) { StackPanel senderObj = sender as StackPanel; if (senderObj != null) { DragDrop.DoDragDrop(senderObj, senderObj.Tag, DragDropEffects.Copy); } e.Handled = true; } private void canvMain_Drop(object sender, DragEventArgs e) { double XPos = e.GetPosition(GlobalImageContainer).X; double YPos = e.GetPosition(GlobalImageContainer).Y; Point targetPoint = new Point(XPos, YPos); Holder targetImage = e.Data.GetData(typeof(Holder)) as Holder;

//如何在此处实现* **

如果(targetImage!= null) { (DataContext作为MainVM).AddToMainContainer(targetImage.ImagePath,targetImage.ImageName,XPos,YPos); } } /*由于我将数据添加到"DataContainer"且已绑定,因此将创建图像,因此它将自动启动Image_Loaded事件.在这里,我必须计算矩阵值,而不是给定的鼠标X和Y坐标. */ 私有void TargetImage_Loaded(对象发送者,RoutedEventArgs e) { image targetImg =发件人为Image; 如果(targetImg!= null) { Holder targetData = targetImg.Tag作为Holder; 如果(targetData!= null) {

if (targetImage != null) { (DataContext as MainVM).AddToMainContainer(targetImage.ImagePath, targetImage.ImageName, XPos, YPos); } } /*Since I am adding data to the "DataContainer" and it is bounded, The image will be created , and so, it will automatically launch the Image_Loaded event. There I have to calculate the Matrix value instead of the given Mouse X and Y coordinates. */ private void TargetImage_Loaded(object sender, RoutedEventArgs e) { Image targetImg = sender as Image; if (targetImg != null) { Holder targetData = targetImg.Tag as Holder; if (targetData != null) {

MatrixTransform matTrans = targetImg.RenderTransform as MatrixTransform; 如果(matTrans!= null) { matTrans.Matrix = new Matrix(targetData.M11,targetData.M12,targetData.M21,targetData.M22,targetData.OffSetX,targetData.OffSetY); } } } }

MatrixTransform matTrans = targetImg.RenderTransform as MatrixTransform; if (matTrans != null) { matTrans.Matrix = new Matrix(targetData.M11, targetData.M12, targetData.M21, targetData.M22, targetData.OffSetX, targetData.OffSetY); } } } }

这就是我正在做的事情.

Here is the snap, of what I am doing.

我可以在操纵增量"内部获得该变换值.事件处理程序,但这仅在拖放之后才被钩住.我也尝试使用这些操作来实现拖放,但是我做不到.

I can get this transformation value inside the "Manipulation Delta" event handlers , but this is hooked only after the drag and drop. I have also tried to achieve the drag and drop using the manipulations but i am unable.

如果我已经完成,那么我可以从操纵增量"获得所有值.如前所述.事件处理程序.

If i have done it, then all values i can get from the "Manipulation Delta" event handler as told earlier.

请允许我知道如何实现此目标,或者是否有其他方法可以获取矩阵值,或者有什么方法可以实现拖放而不是"Touch Down"?和掉落"并通过使用操纵事件.?

May I kindly know how to achieve this,or is there any other way to get the matrix value or is there any way to achieve the drag and drop instead of "Touch Down" and "Drop" and by using the Manipulation events.?

谢谢.

NANDAKUMAR.T

NANDAKUMAR.T

推荐答案

您好NANDAKUMAR T,

Hi NANDAKUMAR T,

>>"但这仅在拖放后才被钩住."

>>" but this is hooked only after the drag and drop."

我看到您已经使用了画布的Drop事件,但是只有在完成转换后才能获得转换值.因此,如果要在移动时获取转换值,则可以尝试使用DragEnter事件.

I saw that you have used Drop event of your canvas, but you could only get the transformation value after you have done it. So if you want to get the transformation value when you were moving, you could try to use DragEnter event.

将数据拖动到放置目标的边界时,将发生DragEnter事件.通常,如果适合您的应用程序,则可以处理此事件以提供拖放操作效果的预览."

"The DragEnter event occurs when the data is dragged into the drop target's boundary. You typically handle this event to provide a preview of the effects of the drag-and-drop operation, if appropriate for your application."

有关详细信息,您可以参考MSDN文档: 拖放概述

You could refer to MSDN document for details: Drag and Drop Overview

>>"有没有其他方法可以获取矩阵值,或者有没有其他方法可以实现拖放而不是"Touch Down"?和掉落"并使用操纵事件."

>>" is there any other way to get the matrix value or is there any way to achieve the drag and drop instead of "Touch Down" and "Drop" and by using the Manipulation events.?"

恐怕您必须在WPF中使用拖放功能,但是如果您不想使用"Touch Down",则可以使用"MouseMove"代替它,就像上面的文档链接一样.

I’m afraid that you have to use Drag and Drop in WPF, but if you didn’t want to use "Touch Down", you could use "MouseMove" to instead it like my above document link.

最好的问候,

Xavier Eoro

Xavier Eoro


这篇关于来自给定鼠标坐标的MatrixTransformations的Matrix值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆