i need to display some images on maps in WP8, that need to stay at their exact position and cover a specific area (these are pictures of buildings that are displayed on a Road Map) but
as far as i know there is no way to make that happen when zooming is allowed.
I can get rid of the Double Tap zooming by simply resetting the zoom level, but i have a problem with pinch zooming because this creates a very ugly jumpy effect.
private void MapTwo_ZoomLevelChanged(object sender, Microsoft.Phone.Maps.Controls.MapZoomLevelChangedEventArgs e)
{
MyMap.ZoomLevel=16;
}
I don't want to disable all user interaction though.
Any advice?
Related
I have a SplitContainer which contains Atalasoft's AnnotateViewer. Class hierarchy is as follows:
System.Windows.Forms.Control
Atalasoft.Imaging.WinControls.ScrollPort
...
Atalasoft.Annotate.UI.AnnotateViewer
My.AnnotateViewer
Now the problem: As long as the content of the SplitContainer is smaller than the actual viewport, hence no scrollbars visible, touch input is interpreted as left mouse down, mouse move and left mouse up which is exactly what I'd expect and love to see. I could still use two-finger-panning to scroll the view. BUT: If I zoom the viewer, so that my content gets larger than my viewport, scrollbars appear and touch input behaves differently: Horizontal panning stays the same, but vertical panning now causes scrolling, even with a single finger.
The question is: Is this behavior Atalasoft-specific, WinForms-specific or system-specific and can I do something to change it? I'd like a single finger to always convert to left click and move. Two finger's for scrolling is fine (and already works.)
I fear that it is system specific because you can find the exact same behavior in Word 2010. Still, it's a Microsoft product.
I begin to hate the fact that you so often get sudden inspiration after finally typing down your problem to a forum or similar.
This problem was now solved by re-registering for gesture events. You are able to register for all pan gestures except for horizontal and/or vertical single finger pan.
// adapt the gesture registration for this window
GESTURECONFIG[] gestureConfig = new[]
{
// register for zoom gesture
new GESTURECONFIG { dwID = GID_ZOOM, dwWant = GC_ZOOM, dwBlock = 0 },
// register for pan gestures but ignore single finger (only use two-finger-pan to scroll)
new GESTURECONFIG { dwID = GID_PAN, dwWant = GC_PAN, dwBlock = GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY }
};
SetGestureConfig(this.Handle, 0, (uint)gestureConfig.Length, gestureConfig, (uint)Marshal.SizeOf(typeof(GESTURECONFIG)));
Details here:
http://msdn.microsoft.com/de-de/library/dd353241%28v=vs.85%29.aspx
I think this is the cleanest solution you can get.
The SetGestureConfig API accepts an GESTURECONFIG struct as its 4th parameter. How can you pass in a GESTURECONFIG[] array?
Currently, I'm using a WPF Image control to display images. I want to do the following: On a MouseUp, MouseDown or MouseMove event, I want to get the coordinates of the point under the cursor, not with reference to the top-left corner of the control, but with respect to the actual coordinates of the displayed bitmap, which may have been re-scaled, or may have a different aspect ratio than the control itself. If an alternate control provides this functionality, I'd be equally happy to hear about it. Thanks in advance.
EDIT: I'd also like so may to know it if the coordinates of the control were out of range of the image, due to a different aspect ratio.
you can get the coordinates of the mouse by this way :
private void image1_MouseDown(object sender, MouseButtonEventArgs e)
{
Point point = e.GetPosition(image1); //position relative to the image
Point point2 = e.GetPosition(this); //position relative to the window
}
Hope that answered a part of your question.
You can use the various TransformTo* methods of the Visual class to get, coordnates relative to a sepcific control, it will take all transformation applied to the visual tree into account.
Also, if you attach MouseUp, MouseDown and MouseMove to the Image control itself, you should already get the correct coordinates from the MouseButtonEventArgs and if you use the mouse outside of the visual bounds of the control, you will not get those events, so you don't need extra code check for coordinates being out of bounds.
If your actual goal is to find out which acutal pixel of your bitmap image has been touched by the mouse (as you would need for a bitmap/pixel editing software) things get much harder because WPF uses virtual device indendent pixels that do not directly relate to pixels on the screen or pixels in a bitmap that has been rendered in an Image control. The Image control internally scales a bitmap image based on the DPI settings of the bitmap file itself and based on the DPI settings of operating system.
How would I draw something on a Canvas in C# for Windows Phone?
Okay, let me be a little more clear.
Say the user taps his finger down at 386,43 on the canvas. (the canvas is 768 by 480)
I would like my application to be able to respond by placing a red dot at 386,43 on the canvas.
I have no prior experience with Canvas whatsoever.
If this is too complex to be answered in one question (which it probably is), please give me links to other websites with Canvas and Drawing articles.
There are various ways of doing this. Depending on the nature of the red dot, you could make it a UserControl. For a basic circle, you can simply handle your canvas' ManipulationStarted event.
private void myCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
Ellipse el = new Ellipse();
el.Width = 10;
el.Height = 10;
el.Fill = new SolidColorBrush(Colors.Red);
Canvas.SetLeft(el, e.ManipulationOrigin.X);
Canvas.SetTop(el, e.ManipulationOrigin.Y);
myCanvas.Children.Add(el);
}
I think you need to approach the problem differently. (I'm not including code on purpose, because of that).
Forms and controls in an Windows applications (including Phone) can be refreshed for several reasons, at any time. If you draw on a canvas in response to a touch action, you have an updated canvas until the next refresh. If a refresh occurs the canvas repaints itself, you end up with a blank canvas.
I have no idea what your end goal is, but you likely want to either keep track of what the user has done and store that state somewhere and show it in a canvas on the repaint of the canvas. This could be done with storing all the actions and "replaying" them on the canvas, or simply storing the view of the canvas as a bitmap and reload the canvas with that bitmap when refreshed. But, in the later case I think using a canvas isn't the right solution.
I am using the .net 4 beta 2 touch libraries, and Im trying to implement a zooming feature in my WPF application.
I can get the zooming working just fine, but what I want is to zoom in on the center of the pinch gesture, and I cannot see anything in the API's about how to accomplish this.
Is there some methods or properties that expose the 2 contacts being using in the pinch gesture so that I can get the center of them?
EDIT:
I just investigated using the GetIntermediateTouchPoints method of TouchEventArgs which did not seem to give me what I want.
Thanks a lot
Mark
Assuming you are using the new TouchXxxxEvent routed events, they all take TouchEventArgs, which has TouchDevice property. If you call its GetTouchPoint() method, you can get the TouchPoint that represents the point of touch.
More details and sample code from Jaime Rodriguez.
Turns out that the properties I was after was right in front of me all along.
the Manipulation2DDeltaEventArgs class has OriginX and OriginX properties that specific the center point of the pinch gesture, so Im just using that and its all good :)
This answer is for .Net 4 release version.
In the case of using ManipulationDelta event the ManipulationDeltaEventArgs.ManipulationOrigin contains center point of the pinch gesture. The coordinates are relative to the ManipulationDeltaEventArgs.ManipulationContainer, which could be set in the handler of ManipulationStarting event.
Example code:
private void object_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
...
// If this was a multitouch gesture
// (like pinch/zoom - indicated by e.DeltaManipulation.Scale)
// the following line will get us point between fingers.
Point position = e.ManipulationOrigin;
...
}
I am trying to make it so that the user can scroll a richtextbox by clicking the window the richtexbox is on and dragging the mouse. Unfortunately I haven't gotten very far:
private void Main_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
}
}
I've seen some suggestions on the web to track the last several x,y coordinates of the mouse and compare them to the x,y coordinates each time the mouse move event is triggered. Is there any less messy way to do this?
None that I know of. Unless you're using an API that handles it for you, you have to keep track of the information manually. And even if you did use an API just for mouse drags, it'd do the storing itself and likely just pass back the current X and Y, and the difference in X and Y, since the API wouldn't know what you want done with the information.
You'd be handling a little bit less information, but saving only about 5 lines or so of code to get the same result.