Exception with INotifyLocationChanged

6 posts, 0 answers
  1. Etienne
    Etienne avatar
    47 posts
    Member since:
    Sep 2014

    Posted 25 Aug 2015 Link to this post

    Hi,

    I use INotifyLocationChanged to raise event when items of a VisualizationLayer move and it throws an exception in some particular case. I've joined a sample project that demonstrate this particular case. I'm I doing something wrong or this is a bug ?

    Thank you,

    Etienne

  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 28 Aug 2015 Link to this post

    Hi Etienne,

    The reported error is caused by the fact that the LocationChanged event is raised for elements that are not added in the VisualizationLayer. In your case the layer with the zones always has two objects, however, the MoveForward command is changing the Location of all zones of all elements which throws an exception in the layer's code.

    In order to prevent the error you will need to ensure that the LocationChanged event in your viewmodel is raised only if the model is added in the layer.

    I hope this information is useful.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Etienne
    Etienne avatar
    47 posts
    Member since:
    Sep 2014

    Posted 28 Aug 2015 in reply to Martin Link to this post

    Hi Martin,

    Thanks for your reply, but I'm not sure how I can do this elegantly. I would have expected that when an item is removed from a layer, the layer unsubscribe from the LocationChanged event or at least ignore future event.

    Regards,

    Etienne

  5. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 01 Sep 2015 Link to this post

    Hi Etienne,

    Since the event handler is manually attached you will need also to manually remove it from the object. However, we will take some time to investigate the observed behavior in the VisualizationLayer's code too. 

    As for avoiding the exception, you can use different approaches based on your application's requirements. I updated your project to demonstrated a possible implementation which you can use. Basically, I defined a Boolean property in the MapItemViewModel that tells if the item has a parent (is it attached somehow to the layer) or not. Then, I am using the property in the condition for raising the LocationChanged event. I made few changes in the following files to set the property when the SelectedThing is changed and when the Things collection is populated:
    • MapItemViewModel.cs
    • ViewModel.cs
    I commented the changed parts of the code. Please give the project a try and let me know if this approach works for you.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Etienne
    Etienne avatar
    47 posts
    Member since:
    Sep 2014

    Posted 11 Nov 2015 in reply to Martin Link to this post

    Hi Martin,

    Is there any update on your side about this ?

    Regards,

    Etienne

  7. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 16 Nov 2015 Link to this post

    Hello Etienne,

    We investigate this and found out this is an issue in RadMap which we logged in our feedback portal. If you follow the item you will be notified as soon as there is any change in its status. We also updated your Telerik points as a small gesture of gratitude for reporting this to us.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready