Note that there are some explanatory texts on larger screens.

plurals
  1. POMapZoom Event not firing for ZoomBar controls
    primarykey
    data
    text
    <p>I have a WP7.1 application with a bing map control on, and I have set the ZoomBarVisibility="Visible" which shows up the plus and minus buttons to control the map zoom. I have then added a MapZoom event, via code and via the xaml and neither event will fire when the zoom buttons are pressed. If I pinch and zoom the events will fire.</p> <p>I have tested this functionality on the phone and the emulator and I get the same results. I'm now thinking that the only way around my issue is to databind to the ZoomLevel property and then raise my own events when this changes.</p> <p>Has anyone else ran into this issue?</p> <p>Below is a copy of my noddy code:</p> <pre><code>&lt;phone:PhoneApplicationPage x:Class="MapTest.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True"&gt; &lt;my:Map x:Name="map2" ZoomBarVisibility="Visible" ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}" MapZoom="map2_MapZoom_1" /&gt; &lt;/phone:PhoneApplicationPage&gt; </code></pre> <p>This is the code behind</p> <pre><code>using System; using System.ComponentModel; using System.Windows; using Microsoft.Phone.Controls; using Microsoft.Phone.Controls.Maps; namespace MapTest { public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged { public MainPage() { InitializeComponent(); map2.MapZoom += (o, args) =&gt; MessageBox.Show("Fired from annoymous delegate"); this.DataContext = this; } private void map2_MapZoom_1(object sender, MapZoomEventArgs e) { MessageBox.Show("Fired from event"); } private int _zoomlevel=50; public int ZoomLevel { get { return _zoomlevel; } set { _zoomlevel = value; RaisePropertyChanged("ZoomLevel"); } } public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged(string propertyName) { if (Deployment.Current.Dispatcher.CheckAccess()) { _RaisePropertyChanged(propertyName); } else { Deployment.Current.Dispatcher.BeginInvoke(new Action&lt;string&gt;(_RaisePropertyChanged), propertyName); } } private void _RaisePropertyChanged(string propertyName) { PropertyChangedEventHandler propertyChanged = PropertyChanged; if ((propertyChanged != null)) { propertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } </code></pre> <p>*<strong><em>Proposed Solution</em>****</strong> Looks like from other comments that its a bug, so I'm going with my proposed solution, which might help someone else out.</p> <pre><code> private int _zoomlevel=50; private int _previousZoomLevel = 50; public int ZoomLevel { get { return _zoomlevel; } set { _previousZoomLevel = _zoomlevel; _zoomlevel = value; RaisePropertyChanged("ZoomLevel"); if (_previousZoomLevel !=_zoomlevel &amp;&amp; MapZoomed != null) MapZoomed(new MapZoomedEventArgs() { PreviousZoomLevel = _previousZoomLevel, ZoomLevel = _zoomlevel }); } } public class MapZoomedEventArgs { public int PreviousZoomLevel; public int ZoomLevel; } </code></pre> <p>The reason for checking the previousZoomLevel is because the property fires multiple times. I can then use this event to handle my MapZoom event rather than the backed in MS version - and as mentioned I can easily swap out the existing ZoomBar for something more exciting and it will still work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload