Is there a way to get mouse and/or touch events on UI elements using Xamarin Forms? So far I only found the TapGestureRecognizer class, but I want the user to be able to move UI elements (PanGestureRecognizer?) but I haven't been able to locate anything that could help me achieve that.
I am looking for a cross-platform solution if possible (hence the user of Xamarin Forms) but I am ok with creating a platform-specific component that integrates with Xamarin Forms (e.g., I already created a custom base page class to add an iOS-specific background gradient page).
I suggest you give MR Gestures a look. It's a Xamarin.Forms component that adds very robust support for gestures. It works on all Xamarin.Forms platforms. From the website:
MR.Gestures adds Down, Up, Tapping, Tapped, DoupleTapped, LongPressing, LongPressed, Panning, Panned, Swiped, Pinching, Pinched, Rotating and Rotated events to each and every layout, cell and view and to the ContentPage. These events will be raised when the user performs the corresponding touch gesture on the element.
It is not free, but at €10 it's a bargain. The documentation is great and the library works exactly as advertised.
Related
I have a somewhat unusual design problem in a WPF touch application.
I have a UserControl that holds an image, which I allow the user to freely move, resize, and rotate around the touch surface using multitouch by setting:
isManipulationEnabled = true
and then hooking up events for ManipulationStarting, ManipulationDelta, and ManipulationCompleted.
This is all good and works perfectly, but now I would like to add the ability for a user to drag this control into the WrapPanel on another control, which has a list of image files, and add this image to the list.
I tried using DragDrop events by calling DragDrop.DoDragDrop() on the ManipulationDelta event, but it locks the UI and the control until a drop occurs, which is not what I want.
Is there any way to properly do this without writing my own hit-testing code? I'm using WPF 4.0 and .NET 4.5 on VS 2013, and I'm not sure if the Surface SDK would help me in this case (nor could I properly install/load it to VS2013)
Found my solution: Use VisualTreeHelper.HitTest and call the HitTest in the event handler for ManipulationDelta, and then use your own logic for handling the drag over operation. Use ManipulationCompleted event to check the hit test again to complete the drop
I´m writing a Kinect WPF application with some special WPF controls (ESRI WPF – especially map control)
Is there any option how to add to this control my own event which will be fired when the hand cursor do something? For example: HandEnter, HandLeave, etc.
I´m not experienced with Events in C# - I´ve never created my own Events – I only know, that there is an AddEvent and AddEventRoute for WPF controls – is this the right way?
Thanks a lot
You may want to look at KinectInteraction in the Kinect for Windows Toolkit 1.7, which supports tracking hands in a physical interaction zone, etc.
However, from your post it seems like it would be a better idea to read up on and experiment with the basics of events and event handling in C# and WPF first. These articles on MSDN may serve as a starting point:
Events (C# Programming Guide)
Events tutorial
Events (WPF)
I'm writing a program to implement COM component in C#. This component provides a UI component too. In the interest of making it easy to implement future additions to the component, I decided to write the UI in Xaml using WPF and wrapping it in an ElementHost control to provide the handle back to to the COM consumer.
Here's where this gets interesting. The element is being hosted in a win32 tab control. The first time the tab is selected, it loads fine. Switching to another tab and coming back causes it to not draw the component correctly. If I move the mouse through it, it'll draw the TextBox elements, but it'll never redraw the whole UserComponent.
I've tried every possible solution I've seen suggested, from changing the height/width values of the component to putting the HwndTarget in SoftwareOnly rendering mode.
I'm not sure what to try at this point, so suggestions are welcome. I'd really like to do this without using Windows Forms as the future maintainers of this aren't the best programmers and it's a lot easier to tell them to write up a Xaml file with data bindings than manually lay out a form and set the values in the code-behind.
Haven't met such problem yet.
Try to force refresh or focus (methods) to the hosting wrapper or HwndSource when switching to the hosting tab.
I have implemented MouseDragElementBehavior to my application before but unfortunately I use the application now using touch panel.
Before, obviously I drag using the mouse, but now because I am using touch panel, the MouseDragElementBehavior won't work.
Is there a way to convert this? My only changes to my application is by using Touch Panel and no changes to my application at all.
The rest like what a mouse can do is also doable by touching but dragging is not supported.
Please help. Thanks
There currently isn't any official Drag for touch. You can however create your own thouch event for such by responding and combining touch events.
PreviewTouchDown For starting your own start drag function on element so add the TouchMove event here to the object
TouchMove For dragging the object visual
PreviewTouchUp For stop dragging stop the TouchMove event here
TouchEnter Check if the object you entered accept drops
Or you can of course google for libraries that already implemented this kind of behavior.
I have googled it a bit and found a good walktrought for windows applications.
And with the Touch Class you can get all the touch points in the application (multiple fingers) and implement your own behavior.
I'd like to get ahead of the pack and start making some custom C# controls and components for Metro (Win8), but I can't find any documentation or blog posts on how to start, or even if it's possible right now.
Are metro controls just WPF controls? I'm not yet a WPF developer; creating a custom user control looks straightforward, but that project type doesn't exist in the Windows 8 developer preview. So, are WPF custom user controls (VS2010) the project type I should use for creating my Metro controls? Beyond that, I can't find any documentation on how to create a component for use in WPF/Metro; can you create one, or would it just be a custom user control that isn't visible? (I was hoping for some type of component container like the one winforms use; are components for Metro now only class libraries, and don't include designer support anymore?)
It's ... very difficult right now. There's no way to override OnRender or the like for a control, ie to create code to render a control with a custom appearance. However, you can create a custom template. Anything you can do in the template is legal, and that's how you have to approach custom controls.
One other option is to generate your UI using either raster (Bitmap) or vector (Windows.UI.Xaml.Shape?) components directly and build up your UI like that. Bleh.
Win8 Metro is a lot like WPF, but it isn't a subset. Similar but very different. Many WPF controls didn't make the transition to Win8 Metro; the same level of rendering control isn't available; and some system features (like advanced font rendering) aren't there. All this might change in coming releases, but right now it looks like Microsoft is trying to restrain developers from creating custom UI controls.