ViewChanged suppress on Windows Phone 8.1 - events

There is a way to fire the event ViewChanged (that was present in previous WP8) within an Windows Phone 8.1 app? I use Windows.UI.Xaml.Controls.Maps and I will manage the map when the view animation finishes.

You can try to use on of these events of the MapControl class:
ManipulationStarted: http://msdn.microsoft.com/en-us/library/hh702372.aspx
CenterChanged: http://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.maps.mapcontrol.centerchanged.aspx
ZoomLevelChanged: http://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.maps.mapcontrol.zoomlevelchanged.aspx
But the best event would be ManipulationCompleted: http://msdn.microsoft.com/en-us/library/windows.ui.xaml.uielement.manipulationcompleted.aspx

I've found that the LoadingStatusChanged event does what you want, provided you check the LoadingStatus first.
mapControl.LoadingStatusChanged += MapLoadingStatusChanged;
private void MapLoadingStatusChanged(MapControl sender, object args)
{
if (sender.LoadingStatus == MapLoadingStatus.Loaded)
{
// code here will only get hit when the map finishes drawing after a pan/zoom
}
}

Related

drag and drop - lag in UWP

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

Xamarin Forms Map Viewable Area event handler

I have a Xamarin form map on my screen and I'm using PropertyChanged event to retrieve geolocation information from my server and display the proper pins on screen.
While coding the solution I noticed the PropertyChanged event is triggered multiple times (up to 10 times) with a single zoom or drag action on the map. This causes unnecessary calls to server which I want to avoid.
Ideally I want to make only one call to server when the final PropertyChanged event is called but I cant's find an easy solution to implement this.
At this point I've added a refresh button to my page that becomes enabled when a PropertyChanged event happens and I disable it after user uses the button.
Obviously this fixed the too many calls to server but made the solution manual.
I was wondering if there is a more elegant way to make the server call but do it automatically.
Thanks in advance.
I just test the PropertyChanged event on iOS side and it just triggered one time with a single zoom or drag action on the map.
While if it really triggered multiple times, you can use a timer to call the server when the final PropertyChanged event is called, for example:
public partial class MapPage : ContentPage
{
Timer aTimer;
public MapPage()
{
InitializeComponent();
customMap.PropertyChanged += CustomMap_PropertyChanged;
}
private void CustomMap_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (aTimer != null)
{
aTimer.Enabled = false;
aTimer.Stop();
aTimer.Close();
}
aTimer = new Timer();
aTimer.Interval = 1000;
aTimer.Enabled = true;
aTimer.Elapsed += ATimer_Elapsed;
aTimer.Start();
}
private void ATimer_Elapsed(object sender, ElapsedEventArgs e)
{
aTimer.Stop();
//do web request
Console.WriteLine(sender);
Console.WriteLine("CustomMap_PropertyChanged");
}
}
In the above code, I set the Interval = 1 second, that means in 1 second, whatever how many times PropertyChanged triggered, only the last call will trigger the ATimer_Elapsed function.
The Interval can be set to any value depending on your requirement.

Windows Moible 6.5 SDK GPS Sample Bugged

I cannot seem to find a good solution for this issue online. I have a device that is running Windows Embedded Handheld 6.5. I run the solution located at below
C:\Program Files (x86)\Windows Mobile 6.5.3 DTK\Samples\PocketPC\CS\GPS
I deploy the code to my device, not an emulator, and the code breaks with a null reference exception at
Invoke(updateDataHandler);
The solution ive seen recommends changing this to below
BeginInvoke(updateDataHandler);
But now the code breaks at Main with NullRefreceException.
Application.Run(new Form1());
Has anyone found a solution for this?
Did you alter the code? updateDataHandler is initialized in Form_Load:
private void Form1_Load(object sender, System.EventArgs e)
{
updateDataHandler = new EventHandler(UpdateData);
so that object will not be NULL. But there are other annoyances with the code, especially the Samples.Location class. You may instead use http://www.hjgode.de/wp/2010/06/11/enhanced-gps-sample-update/ as a starting point and the older one: http://www.hjgode.de/wp/2009/05/12/enhanced-gps-sampe/
The main issue with the sample is that it does not use a callback (delegate) to update the UI. If an event handler is fired from a background thread, the handler can not directly update the UI. Here is what I always use to update the UI from a handler:
delegate void SetTextCallback(string text);
public void addLog(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.txtLog.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(addLog);
this.Invoke(d, new object[] { text });
}
else
{
txtLog.Text += text + "\r\n";
}
}

Mono GTK# - PropertyNotifyEvent of window or widget

I want to be able to react if a property of a given window or widget has been changed and found the Gtk.Widget.PropertyNotifyEvent event. The (mono) documentation says that it will be fired if any property has been changed. So I've tried to make use of it but my event handler method is never invoked:
protected void DoSomething()
{
Gtk.Window __Window = new Gtk.Window(Gtk.WindowType.Toplevel);
Gtk.Button __Button = new Gtk.Button();
__Window.Add(__Button);
__Button.PropertyNotifyEvent += this.ButtonPropertyChangedEventHandler;
... // Show the window
__Button.Label = Mono.Unix.Catalog.GetString("This is a test button");
}
protected void ButtonPropertyChangedEventHandler(object o, PropertyNotifyEventArgs e)
{
// Handle the event
}
Do I miss something? Or did I understand something very basic wrong? Or is there another approach to achieve my goal?
Property change notifications need to be explicitly enabled by setting the GDK_PROPERTY_CHANGE_MASK flag, as explained here:
https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-property-notify-event
In Gtk# you just need to add the following line to your code:
__Button.Events |= Gdk.EventMask.PropertyChangeMask;
And the handler assigned to the PropertyNotifyEvent event will start to receive property change notifications. Gtk# enables some events implicitly but all others should be enabled from user code or from the stetic designer.

How can the application only support "LandscapeLeft" oritation in windows phone 7?

I wrote a application. I need it to support only LandscapeLeft orientation. My xaml looks like this:
SupportedOrientations="Landscape"
Orientation="LandscapeLeft"
However, when I turn the phone to LandscapeRight, the page turns automatically. I have overridden the OnOrientationChanged function, but it doesn't work.
How can I make it work?
It's not recommended support only landscape left, but if you want this, your override method should be similar to this:
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.LandscapeLeft)
{
base.OnOrientationChanged(e);
}
}

Resources