Hi to all I'm trying to set a listener for the ManipulationStarted, ManipulationDelta, ManipulationCompleted of a map to detect if the user drag a map around, but looks like none of those events are launched if I drag the map. If I set a tap listener for the map ManipulationStarted is correctly launched.
What I'm doing wrong?
xaml code:
<Controls:Map x:Name="myMap"
Grid.Row="0"
Loaded="myMap_Loaded"
ManipulationDelta="myMap_ManipulationDelta"
ManipulationCompleted="myMap_ManipulationCompleted"
ManipulationStarted="myMap_ManipulationStarted"
Tap="myMap_Tap">
code behind:
private void myMap_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationdelta");
}
private void myMap_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationcompleted");
}
private void myMap_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
{
Debug.WriteLine("Event:: MyMap_manipulationstarted");
}
private void myMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Debug.WriteLine("Event:: MyMap_tap");
}
I'm on a normal page, no pivot or panorama.
I'm afraid that you won't be able to handle those events because Map control intercepts them. Although there is a property UseOptimizedManipulationRouting, but as I've tested it - it doesn't help much in this situation.
I dont't know what you are trying to achieve, but if you don't need ManipulationDeltaEventArgs then maybe you consider using different events such as: MouseEnter, ResolveCompleted and CenterChanged.
If you need them then as JustinAngel suggested here you can follow these instructions and use Touch.FrameReported event for your purpose.
EDIT - code sample
If I've understood you properly, you would like to know when the User touches the Map, MouseEnter won't be the best choice as it will work only first time, then if mouse didn't leave the Map (user touched somewhere else), it won't fire again. Better solution here (following instructions above) can be such a code:
public MainPage()
{
InitializeComponent();
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint point = e.GetPrimaryTouchPoint(myMap);
if (point.Action == TouchAction.Move && point.Position.Y > 0)
{
MessageBox.Show("User is Moving Finger over the Map!");
}
}
Related
Hello drag and drop fans,
Can anyone explain why I see a long lag time when using drag and drop with my UWP apps?
I wrote a test app that contains just the drag and drop message handlers and also the pointer handlers for comparison. Here’s the code...
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
grid1.AllowDrop = true;
grid1.DragOver += Grid1_DragOver;
grid1.Drop += Grid1_Drop;
grid1.DragLeave += Grid1_DragLeave;
grid1.PointerEntered += Grid1_PointerEntered;
grid1.PointerExited += Grid1_PointerExited;
}
// Drag Handlers ************************
private void Grid1_DragOver(object sender, DragEventArgs e)
{
msgFromPointer.Text = " drag/drop item has entered";
e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Copy;
Debug.WriteLine("in grid1 drag over handler");
}
private void Grid1_DragLeave(object sender, DragEventArgs e)
{
msgFromPointer.Text = "";
}
private void Grid1_Drop(object sender, DragEventArgs e)
{
Debug.WriteLine("in grid1 drop handler");
}
// pointer handlers *******************
private void Grid1_PointerEntered(object sender, PointerRoutedEventArgs e)
{
msgFromPointer.Text = "POINTER has entered";
}
private void Grid1_PointerExited(object sender, PointerRoutedEventArgs e)
{
msgFromPointer.Text = "";
}
When doing a drag and drop to my app, there seems to be about a 1/2 second delay before my app receives the dragOver message. In comparison, the pointerOver message seems to arrive almost simultaneously with the pointer movement. The slow behavior is the same when using the touch screen or a mouse. Here’s a video of the behavior…
video of the laggy behavior
The PC I’m using has a touch screen and I’m wondering if there is some sort of touch “driver” or filter that is slowing down the drag and drop message. I've tried a bunch of Windows config settings, like mouse and display settings, but no change. The PC is a Dell Inspiron 3593, with the latest drivers. My Windows 10 version is 1903, build 18362.836
The app I’m developing uses a lot of drag and drop and this slow behavior makes the user interface really difficult. It’s kind of like trying to conduct a phone conversation with a 1/2 second delay.
Any ideas?
Dan
The DragOver event is triggered when the application determines that the element under the current pointer is a potential placement target.
This requires the pointer to hover for a period of time. This may be the reason for the delay you think.
You can try the DragEnter event, which is triggered earlier than DragOver.
Thanks
I quickly made a Windows Forms project which loads a GUI of different textboxes with float values. Some of them do have already a value initialized. All textboxes have to be updated after one of them is changed.
public Form1()
{
InitializeComponent();
initializeValues();
calculateValues();
}
public void initializeValues()
{
//textboxes are filled/initialized with default float values
}
public void calculateValues()
{
//here all textboxes are new calculated and updated
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
calculateValues();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
calculateValues();
}
Problem:
When I execute this project, it throws me a StackOverflowException which is unhandeled (infinite loop or infinite recursion). I think it's because during the calculateValues() method the text of the textBoxes will be changed and then the Eventhandlers are activated. That's the infinite loop :-(
How I have to change my code construct above to avoid this?
Thanks.
You should not using and calling "initializeValues();" (the cause of the infinite loop).
A first solution could be to put the init value of a TextBox in InitializeComponent :
MyTextBox.Text = myInitValue;
I solved the problem by changing the Event to "KeyPress". In this case, the Event is not activated by the method itself. No more infinite loops. Setting breakpoints and step through helped me to understand "the flow". Thanks CodeCaster.
I have the below event that gets fired upon geocoordinatewatcher object position changed event.
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
//do the stuff here
}
Now when user clicks on any location on the map I want to call the above method and do the same stuff everytime.
Any idea how do I achieve this ?
Either call your event handler manually:
var position = new GeoPosition<GeoCoordinate>(DateTimeOffset.Now, new GeoCoordinate(32, 64));
this.watcher_PositionChanged(this, new GeoPositionChangedEventArgs<GeoCoordinate>(position));
Or rewrite your event handler to put the logic in another method, then call it:
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
this.UpdatePosition(e.Position);
}
private void UpdatePosition(GeoCoordinate coordinates)
{
// Do the stuff here
}
This way, you just have to call UpdatePosition whenever you feel like it. I'd recommend this solution, it's way cleaner than the first one.
Could you show me the way or the idea how to execute biding data every 10s??
Let's see the code below:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
proxy.DanhSachPhongChoiCompleted += new
EventHandler<DanhSachPhongChoiCompletedEventArgs>(proxy_DanhSachPhongChoiCompleted);
proxy.DanhSachPhongChoiAsync();
}
void proxy_DanhSachPhongChoiCompleted(object sender, DanhSachPhongChoiCompletedEventArgs e)
{
Room[] table = e.Result;
listDSPhong.ItemsSource = e.Result;
}
We can see: ater my page loaded, the binding data will execute ONLY ONE TIME. I need to call 2 methods below every 10s. How should I do? Thanks for teaching me!
proxy.DanhSachPhongChoiCompleted += new
EventHandler<DanhSachPhongChoiCompletedEventArgs>(proxy_DanhSachPhongChoiCompleted);
proxy.DanhSachPhongChoiAsync();
You can use e.g. DispatcherTimer class.
Here's the sample:
https://stackoverflow.com/a/3266071/126995
You better start your timer in NavigatedTo, and kill it in NavigatedFrom.
P.S. I suspect there's a memory leak in your code. Please read this.
you can use Microsoft's reactive library
http://msdn.microsoft.com/en-us/data/gg577609.aspx
and do something like this :
public void callfunction()
{
IScheduler scheduler = NewThreadScheduler.Default;
scheduler.Schedule(TimeSpan.FromSeconds(5), new Action<Action<TimeSpan>>(myRepeatingFunction));
}
private void myRepeatingFunction(Action<TimeSpan> action)
{
//process here
action(TimeSpan.FromSeconds(5)); // five second interval
}
I am using the latest Phone 7 RTM tools ( downloaded it today, October 7 2010).
I am trying to do a simple thing here:
when the user taps once on the map control, i want to put a pushpin there.
also, i want to keep the regular built-in behavior of the map control ( tap twice to zoom).
(If it's not possible to keep both behaviors , then maybe a long press on the map to put pushpin).
When trying figuring this out, i came across this documentation of the changes made to the control map for Phone7:
http://msdn.microsoft.com/en-us/library/ff955762.aspx
Then i saw the new class MapInputEventArgs, which has a ViewportPoint member.
When looking at code examples on the regular SilverLight map control i saw something like this:
private void OnMouseClick(object sender, MapMouseEventArgs e)
{
Point clickLocation = e.ViewportPoint;
Location location = x_Map.ViewportPointToLocation(clickLocation);
Pushpin pushpin = new Pushpin();
m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude));
}
But in Phone7 case, I can't find the appropriate event handler, and I could not find who uses MapInputEventArgs in the map control.
Searching it on google gets me only 1 result !!
So , where is the appropriate event for "Tap once", and how can i get a ViewportPoint after this event has been fired ?
Thanks in advance.
Just figured this out if you are still having problems.
The MouseLeftButtonUp and MouseLeftButtonDown Events have a GetPosition Method that will return the point your looking for
private void MapMain_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Point p = e.GetPosition(this.MapMain);
GeoCoordinate geo = new GeoCoordinate();
geo = MapMain.ViewportPointToLocation(p);
MapMain.ZoomLevel = 17;
MapMain.Center = geo;
//---create a new pushpin---
Pushpin pin = new Pushpin();
//---set the location for the pushpin---
pin.Location = geo;
//---add the pushpin to the map---
MapMain.Children.Add(pin);
}
Unless I'm reading your question wrong, this seems to be exactly what you're looking for:
Silverlight - Add Pushpin to Bing Maps via C#
Okay, it's not pretty, but I have the same problem and I came up with a workaround of sorts that kicks in when you release your fingers from the screen. I instantiate a boolean:
bool noPin = false;
I then use this to determine whether zoom or pan is being done by the user (these fire between the MouseLeftButtonDown and MouseLeftButtonUp events). On the Up event, I then check whether the user was zooming or panning and, if not, place my pushpin.
private void mHome_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
noPin = false;
}
private void mHome_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (!noPin)
PlacePushPin();
}
private void mHome_MapPan(object sender, MapDragEventArgs e)
{
tbTemp.Text += "pan";
}
private void mHome_MapZoom(object sender, MapZoomEventArgs e)
{
tbTemp.Text += "zoom";
}
It's not beautiful but, well, it was the best I could manage.