Dynamic Layer Example : "Must create DependencySource on same Thread as the DependencyObject."}

8 posts, 0 answers
  1. Julien
    Julien avatar
    11 posts
    Member since:
    Mar 2015

    Posted 05 Feb Link to this post

    Hi,

    I take the Dynamic Layer example and i try to replace the points by the polylines.

    internal List<PolylineData> GetFeatures(
                double upperLeftLat,
                double upperLeftLong,
                double lowerRightLat,
                double lowerRightLong,
                GeomType storeType)
            {
                try
                {
                    PolylineData polyline1 = new PolylineData()
                    {
                        ShapeFill = new MapShapeFill()
                        {
                            Stroke = new SolidColorBrush(Colors.Red),
                            StrokeThickness = 2
                        }
                    };
     
                    LocationCollection pt = new LocationCollection
                    {
                        new Location(44.6957539183824, 23.3327663758679),
                        new Location(44.1429369264591, 24.7498095849434),
                        new Location(44.5131732087098, 27.4611884843576),
                        new Location(45.2073941930888, 27.9275176988258)
                    };
     
                    polyline1.Points = pt;
                    _listPolylineDatas.Add(polyline1);
                    return _listPolylineDatas;

     

    But i have an exception : {"Must create DependencySource on same Thread as the DependencyObject."}

    Do you have an solution for this issue ?

     

    Thank you

  2. Julien
    Julien avatar
    11 posts
    Member since:
    Mar 2015

    Posted 09 Feb in reply to Julien Link to this post

    The issue comes from this line : request.CompleteItemsRequest(list); Do you have a solution for the dynamic data ?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 09 Feb Link to this post

    Hello Julien,

    I wasn't able to reproduce the reported exception. However, keep in mind that the MapShapData object as PolylineData are designed to work asynchronously inside a VisualizationLayer. On the other hand the DynamicLayer works on a single thread which might causes the issue.

    I recommend you to use MapShape along with the DynamicLayer or MapShapeData only with the VisualizationLayer. The VisualizationLayer is the new shapes rendering engine of the map which combines the old layers (VirtualizationLayer, DynamicLayer, InformationLayer). The new layer has improved performance and also few new features as reading shape files async and built-in selection. 

    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
  5. Julien
    Julien avatar
    11 posts
    Member since:
    Mar 2015

    Posted 09 Feb in reply to Martin Link to this post

    OK. Can you share an example ?

    Thx

  6. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 09 Feb Link to this post

    Hello,

    You can take a look at the Items Virtualization and Map Shapes Virtualization help articles. The UI Virtualization demo also will be helpful.

    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
  7. Julien
    Julien avatar
    11 posts
    Member since:
    Mar 2015

    Posted 09 Feb in reply to Martin Link to this post

    Thank you Martin for your information.

        

         
    internal List<PolylineData> GetPolylineDatas(
        double upperLeftLat,
        double upperLeftLong,
        double lowerRightLat,
        double lowerRightLong,
        GeomType storeType)
    {
            PolylineData polyline1 = new PolylineData()
            {
                ShapeFill = new MapShapeFill()
                {
                    Stroke = new SolidColorBrush(Colors.Red),
                    StrokeThickness = 2
                }
            };
     
            LocationCollection pt = new LocationCollection
            {
                new Location(44.6957539183824, 23.3327663758679),
                new Location(44.1429369264591, 24.7498095849434),
                new Location(44.5131732087098, 27.4611884843576),
                new Location(45.2073941930888, 27.9275176988258)
            };
     
            polyline1.Points = pt;
            _listPolylineDatas.Add(polyline1);
            return _listPolylineDatas;

    After this function, i call SetPolylinesFeatures:

    internal void SetPolylinesFeatures(List<PolylineData> list, MapItemsRequestEventArgs request)
            {
                request.CompleteItemsRequest(list);
            }

     

    And i have this issue: Must create DependencySource on same Thread as the DependencyObject

     

  8. Julien
    Julien avatar
    11 posts
    Member since:
    Mar 2015

    Posted 10 Feb in reply to Julien Link to this post

    Do you have a solution ?

    Thank you

  9. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 11 Feb Link to this post

    Hello Julien,

    It seems that the reported exception is thrown because the ShapeFill of the PolylineData object is set before the polyline is rendered in the visualization layer. The ShapeFill property accepts an object of type MapShapeFill which is a dependency object bound in the template of the map shape data elements. As the error states you cannot create a DependencyObject (the UIElement that represents the shape) on a different thread than the one on which is created the dependency source (the MapShapeFill object). On the other hand the layer works with the MapShapeData objects in different threads which causes the issue. 

    To work this around you can avoid setting the MapShapeFill property of the MapShapeData elements and instead use the ShapeFill property of the VisualizationLayer. Also, you can take a look at the Graph Colorizer and Colorizer help articles.

    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