This is a migrated thread and some comments may be shown as answers.

MapEllipseView ShapeFill only renders on hover

2 Answers 105 Views
Map
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 04 Jan 2017, 11:08 AM

Hello,

I have a VisualizationLayer bound to a collection of objects, which each have their own colour accessible via a property. I've defined a MapEllipseView for (some of) the objects in the collection via an ItemTemplateSelector. The MapEllipseView has its ShapeFill property bound to the colour, and I use a converter to convert from the Color object to a MapShapeFill object, i.e. ShapeFill="{Binding Color, Converter={StaticResourceEllipseFillConverter}}".

The issue I have is that when I add items to the collection the ellipses are rendered on the map, but the ShapeFill doesn't actually take effect until I hover over each ellipse in turn, so I  need to "colour them in" with the mouse. Through debugging I've worked out that it accesses the property when an item is added to the collection, and when I hover over it doesn't access it again, so the map has clearly already obtained the colour it should be displaying, it's just not rendering it.

Is this a bug or is there something I can do to fix this?

Thanks,

Chris

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 06 Jan 2017, 11:54 AM
Hi Chris,

The bindable wrappers of RadMap (as MapEllipseView) have few known issues. One of those is that the bindings to the ShapeFill property of the wrapper, doesn't work as you would expect. In order to update the fill of the shape you will need to manually call the UseRegularFill() method of the wrapper's data object. In your case this is EllipseData. The method should be called on each update of the property.

Instead, of using a converter, you can try an attached property bind to the color from your view model. When the color changes you can use the PropertyChanged callback of the attached property, convert the color to MapShapeFill and call the method. For example:
<telerik:MapEllipseView local:MyMapUtilities.ShapeColor="{Binding Color}" />

public class MyMapUtilities
{
    public static readonly DependencyProperty ShapeColorProperty =
      DependencyProperty.RegisterAttached(
          "ShapeColor",
          typeof(Color),
          typeof(MyMapUtilities),
          new PropertyMetadata(null, OnShapeColorChanged));
    public static Color GetShapeColor(DependencyObject obj)
    {
        return (Color)obj.GetValue(ShapeColorProperty);
    }
    public static void SetShapeColor(DependencyObject obj, Color value)
    {
        obj.SetValue(ShapeColorProperty, value);
    }         
    private static void OnShapeColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var wrapper = (MapEllipseView)d;
        var color = (Color)e.NewValue;
        var fill = new MapShapeFill() { Fill = new SolidColorBrush(color) };
        wrapper.ShapeFill = fill;
        wrapper.ShapeData.UseRegularFill();
    }
}

Regards,
Martin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Chris
Top achievements
Rank 1
answered on 06 Jan 2017, 03:55 PM

Hi Martin,

Thanks very much for that workaround, it's now behaving as I want it to. One small change I had to make to your code was where you specify null as the default value in the property metadata. Because Color is a struct it caused an exception, so I changed it to "new Color()".

Chris

Tags
Map
Asked by
Chris
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Chris
Top achievements
Rank 1
Share this question
or