Does MapCircle support data binding?

Hello,

I want to show a point on the map. I want to show the location of this point by data binding path.

I have a xaml code like below. While binding data to ImagerLayer, midpoint shows null when binding to MapCircle.


Center="{Binding DevicePoint}"

Fill="Blue"/>




ViewModel

public Point DevicePoint

{

get => _devicePoint;

set => SetProperty(ref _devicePoint, value);

}


Error : Cannot find governing FrameworkElement or FrameworkContentElement for targer element.



3 Replies 1 reply marked as answer

VR Vignesh Ramesh Syncfusion Team December 31, 2021 12:11 PM UTC

Hi Özgür, 

The MapCircle is an object class that does not part of the logical tree of Map. So, resources and bindings can't walk up the tree to resolve its references and are unable to bind it from the ViewModel. 

We recommend you, add the Center from the XAML file or create a complete MapCircle in the ViewModel and bind it to the Map's MapElements property as shown in the below snippet. 

XAML: 
<Window.DataContext> 
    <mapwpf:ViewModel /> 
</Window.DataContext> 
 
<maps:ImageryLayer.SubShapeFileLayers> 
    <maps:SubShapeFileLayer x:Name="subLayer" 
                            MapElements="{Binding MapElements}"> 
    </maps:SubShapeFileLayer> 
</maps:ImageryLayer.SubShapeFileLayers> 

[C#]: 
In ViewModel.cs 

public ObservableCollection<MapElement> MapElements { get; set; } 

… 
public ViewModel() 
{ 
    this.DevicePoint = new Point(43.76140927456403, -79.35451013248883); 
    this.MapElements = new ObservableCollection<MapElement>(); 
    var mapCircle = new MapCircle 
    { 
        Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3eFF0000")), 
        Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#73FF0000")), 
        StrokeThickness = 3, 
        Radius = 110 
    }; 
 
    Binding binding = new Binding(); 
    binding.Source = this; 
    binding.Path = new PropertyPath(nameof(this.DevicePoint)); 
    BindingOperations.SetBinding(mapCircle, MapCircle.CenterProperty, binding); 
 
    this.MapElements.Add(mapCircle); 
} 

We have prepared the sample for the same. Please get it from the below link. 

Please let us know if you need any further assistance. 

Regards, 
Vignesh Ramesh. 


Marked as answer

ÖZ Özgür January 6, 2022 07:23 AM UTC

Thank you for answer. It's work.



ET Eswaran Thirugnanasambandam Syncfusion Team January 6, 2022 11:46 AM UTC

Hi Özgür, 
 
We are glad to hear that the provided solution resolved the problem. Please get in touch with us if you would require any further assistance.  
 
Regards, 
Eswaran 


Loader.
Up arrow icon