locked
Anyway to make a binding RRS feed

  • Question

  • I tried to make a binding of center property and I have the following exception:

    An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in GSC.Metro.MapImages.UI.exe but was not handled in user code

    WinRT information: Failed to assign to property 'Bing.Maps.Location.Latitude'. [Line: 97 Position: 45]

    Additional information: Unspecified error

    the XAML was:

           	    <Maps:Map Grid.Column="1" Margin="12,0,0,0" Credentials="" ZoomLevel="7">
                    <Maps:Map.Center>
                        <Maps:Location Latitude="{Binding CenterLatitude}" Longitude="{Binding CenterLongitude}" />
                    </Maps:Map.Center>
                </Maps:Map>
    

     

    Alberto Diaz Martin twitter://@adiazcan | http://geeks.ms/blogs/adiazmartin | MVP SharePoint Server

    Thursday, June 7, 2012 12:21 PM

Answers

All replies

  • In stead try something like this:

    <Maps:Map Center="{Binding CenterLocation}"/>

    Create a public Location object called CenterLocation and bind to it.


    http://rbrundritt.wordpress.com

    Thursday, June 7, 2012 2:10 PM
  • Hi Richard,

    the same error, I create a Bing.Maps.Location variable with a valid latitude and longitude, and bind it to the Center property.

    Thanks!


    Alberto Diaz Martin twitter://@adiazcan | http://geeks.ms/blogs/adiazmartin | MVP SharePoint Server

    Thursday, June 7, 2012 2:21 PM
  • Center (and a bevy of other speed sensitive properties) are no longer databindable for performance reasons. Updating them every frame proved to be an unacceptable decrease in performance.
    Thursday, June 7, 2012 3:33 PM
  • Hi Kristoffer,

    I understand this on properties like Center and Zoom, but what about Pushpin?

    Will we have any way to bind a pushpin collection of items?

    Regards,


    Alberto Diaz Martin twitter://@adiazcan | http://geeks.ms/blogs/adiazmartin | MVP SharePoint Server

    Thursday, June 7, 2012 3:42 PM
  • It would be nice to have to help with usability but I can't give a date on when we will have it.
    Thursday, June 7, 2012 5:39 PM
  • Will we have any way to bind a pushpin collection of items?

    I've just installed the new Bing Maps for Windows 8 Metro Style.

    Is it true, that Microsoft moving away from the concept of binding of pushpin collections?
    This would kill every modern development way of separation on concerns (MVVM). Back to ugly code behind.

    Regards
    Dirk

    Friday, June 8, 2012 11:30 AM
  • While I understand that performance is a critical deliverable, I think that preventing these properties from being databindable is the wrong way to achieve this. You are making it very difficult to build a Metro style app incorporating Bing Maps using MVVM.

    While frequent updates of these properties can cause performance problems, it should be up to the app developer to limit the frequency of updates to an underlying ViewModel, not you preventing that situation by making it impossible.

    In any case, I thought databinding was essentially event driven (INotifyPropertyChanged) so how is it you are updating them every frame?  If it's two-way databinding that is the issue and you are concerned about the volume of updates going from the control to the underlying data object, well can't you just throttle the number of PropertyChanged events you fire from the control?  [I suppose it's not that simple].

    I'm disappointed by this decision.

    Andy Wigley  - Windows Phone Development MVP

    Friday, June 8, 2012 1:17 PM
  • The problem is not the developer doing frequent updates, though that would exacerbate the performance problem. Since DependencyProperties are push modelled we needed to set Center, ZoomLevel etc after every view change event which is potentially every frame. During an animation is when framerate drops are most noticable but also when these properties would need to be updated every frame. This proved to be the difference between 30 frames per second and 15 on low end hardware. If there was a one way databind to one of these framerate would drop into single digits.

    It really was a choice between performance and usability. Previously every developer would see worse performance even if they did not touch any properties of the map. Now that these properties are not backed by a DependencyProperty they have no overhead unless the app developer chooses to get/set them every frame.

    Friday, June 8, 2012 4:19 PM
  • I agree with Andy, this is not the correct decision. Data binding is critical to well factored MVVM applications where you have designers working in hand with developers. The first thing developers have to do is wire up an "on-changed" style event which updates their model and then wire up code which updates the map position when their model changes. You've broken the fundamental databinding capability. Please fix


    Nick Randolph ~ Built to Roam

    Saturday, June 9, 2012 6:33 AM
  • At least it's not only a problem of the bad supported MVVM pattern in the Bing Map component of Windows 8 metro style.

    It's a problem of the complete WinRT framework which supports the MVVM pattern less then Silverlight ever did.
    For Silverlight (and Silverlight for Windows Phone 7) the community could develop great helper classes for MVVM frameworks (Caliburn, MVVM Light) to support us developer to separate UI and Business Logic. But WinRT doesn't even support Behaviours to build a workaround for example things like EventToCommand objects. 

    I'm looking forward what the P&P Team will do to offer MVVM support with PRISM. Will they?

    IMHO the WinRT framework will in the moment not target developing serious LOB applications.

    But thanks to Kristoffer for his support in this forum.
    Maybe we find togehter workarounds..

    Regards
    Dirk

    Saturday, June 9, 2012 2:38 PM
  • I also look at this at a big step backwards from what we had in the Silverlight Bing maps where I could use binding with my Pushpins but it is consistent with the rest of metro which being build for real simple apps and architecture takes a less important role. The masses really do not care they only want their app built quickly and easily. I mean why else would JavaScript be front and center. Too bad as Apple gives u both as XCode enforces an MVC pattern and even Javacript frameworks like Sencha are build around MVC and Observables. You can do both and  I think must do both or else quality will suffer

    so my Silverlight xaml/cs looked like:

     <Bing:Map     VerticalAlignment="Stretch"   HorizontalAlignment="Stretch"  x:Name="map1"    
                    CredentialsProvider="{Binding CredentialsProvider}"
                      ZoomLevel="{Binding Zoom}" TargetViewChanged="map1_TargetViewChanged"
                     >
                        <Bing:MapItemsControl x:Name="MapItems" ItemsSource="{Binding Pushpins}">
                            <Bing:MapItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Bing:Pushpin Style="{StaticResource PushpinStyle}"  
                                            MouseLeftButtonUp="Pushpin_MouseLeftButtonUp"
                                            Location="{Binding Location}"
                                            Background="{Binding Path=Self, Converter={StaticResource PushpinTypeBrushConverter}}"
                                           >
                                        <Image Source="{Binding Icon}" />
                                    </Bing:Pushpin>
                                </DataTemplate>
                            </Bing:MapItemsControl.ItemTemplate>
                        </Bing:MapItemsControl>
    
                    </Bing:Map>

    then I just bind to my the lat and longs in my DataContext is now reduced to:

    <bm:Map x:Name="MyMap"
                    TabIndex="1"
                Grid.Column="0" >
            </bm:Map>

    and most of logic in codebehind

      MyMap.Center = new Location(Double.Parse(cams[0].Latitude), Double.Parse(cams[0].Longitude));
                MyMap.ZoomLevel = 13;
        //        MyMap.Children = cams;
    
                foreach (Camera cam in cams)
                {
                    Pushpin pushpin = new Pushpin();
                    pushpin.Text = "1";
                    pushpin.Tapped += pushpin_Tapped;
                    MapLayer.SetPosition(pushpin, new Location(Double.Parse(cam.Latitude), Double.Parse(cam.Longitude)));
                    MyMap.Children.Add(pushpin);
    
                }


    john mcfetridge



    Monday, June 11, 2012 3:30 PM
  • This really is an appalling decision. We've got maps in Windows Phone 7 with 20+ databound points and polylines, and performance is ok. Surely you're not saying that perf on Windows 8 is worse than perf on WP7?


    Monday, July 9, 2012 9:35 PM
  • This really is an appalling decision. We've got maps in Windows Phone 7 with 20+ databound points and polylines, and performance is ok. Surely you're not saying that perf on Windows 8 is worse than perf on WP7?


    I've made a start on 'MapManager', an open source initiative to extend Bing Maps for Metro to support this kind of thing; I don't have direct databinding, but it is more of an MVC model, for example, you can make any object implement IMapAnnotation and then add these objects to the map.  

    Take a look at the source; perhaps we could update IMapAnnotation to use an event-driven model to simulate data-binding?  Or some sort of observable property?

    https://github.com/carlospuk/metromapmanager


    _______________________________ Carl Partridge

    Tuesday, July 10, 2012 2:39 PM
  • or look here:

    https://bindablemaprt.codeplex.com

    wrapper to use databindings again.

    Wednesday, July 18, 2012 5:06 PM
  • Tuesday, October 2, 2012 10:14 PM