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

Binding

4 Answers 117 Views
Map
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 18 Oct 2012, 09:20 PM
I am trying to draw some polygons and within the polygons I want to put information about the polygon.  

Eventually I will have multiple textblocks in the stackpanel.  I don't understand how to bind to my additional data.  I am using MVVM and my polygon binds good to Points. 

If I change the textblock to 
<TextBlock Text="Test" /> the textblock will show in the polygon with Test.  Output does not show any binding issues, it just doesn't work.  

<
telerik:RadMap x:Name="radMap" Center="49.002049,-101.367682" ZoomLevel="8" Width="1350" Height="700">
<telerik:InformationLayer x:Name="infoLayer" ItemsSource="{Binding Model.Items}">
    <telerik:InformationLayer.ItemTemplate>
        <DataTemplate>
        <telerik:MapPolygon Points="{Binding Points}" Fill="Green" >
        <telerik:MapPolygon.CaptionTemplate  >
            <DataTemplate>
                <StackPanel Background="Yellow" >
                        <TextBlock Text="{Binding SubItem}" />
                </StackPanel>
            </DataTemplate>
        </telerik:MapPolygon.CaptionTemplate>
        </telerik:MapPolygon>
        </DataTemplate>
    </telerik:InformationLayer.ItemTemplate>
</telerik:InformationLayer>
</telerik:RadMap>



4 Answers, 1 is accepted

Sort by
0
Steve
Top achievements
Rank 1
answered on 18 Oct 2012, 09:29 PM
Sorry, this should be in the Silverlight > Map section, not WPF > Map.  
0
Andrey
Telerik team
answered on 23 Oct 2012, 11:36 AM
Hello Steve,

Presently, you can't use the CaptionTemplate this way. It allows using the databinding to the ExtendedData property of the MapShape only. I would recommend using additional information layer for displaying the caption. The sample code is below.
<telerik:RadMap x:Name="radMap" Center="49.002049,-101.367682" ZoomLevel="8" Width="1350" Height="700">
    <telerik:InformationLayer x:Name="infoLayer" ItemsSource="{Binding Model.Items}">
        <telerik:InformationLayer.ItemTemplate>
            <DataTemplate>
                <telerik:MapPolygon Points="{Binding Points}" Fill="Green" />
            </DataTemplate>
        </telerik:InformationLayer.ItemTemplate>
    </telerik:InformationLayer>
    <telerik:InformationLayer x:Name="captionLayer" ItemsSource="{Binding Model.Items}">
        <telerik:InformationLayer.ItemTemplate>
            <DataTemplate>
                <StackPanel Background="Yellow" telerik:MapLayer.Location="{Binding SubItemLocation}">
                    <TextBlock Text="{Binding SubItem}" />
                </StackPanel>
            </DataTemplate>
        </telerik:InformationLayer.ItemTemplate>
    </telerik:InformationLayer>
</telerik:RadMap>

Greetings,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Steve
Top achievements
Rank 1
answered on 23 Oct 2012, 08:13 PM
Thanks for the information, I'll try that.  

In addition, I found when trying to color the polygons like this:

<telerik:MapPolygon Points="{Binding Points}" Fill="{Binding ForegroundColor}" >
private static readonly PropertyInfo<System.Windows.Media.Brush> _ForegroundColorProperty = RegisterProperty<System.Windows.Media.Brush>(p => p.ForegroundColor, string.Empty);
public System.Windows.Media.Brush ForegroundColor
{
  get
  {
    System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush();
    brush.Color = Colors.Black;
 
    if (this.Criteria == "CA")
        brush.Color = Colors.Blue;
 
    else if (this.Criteria == "NO")
        brush.Color = Colors.Red;
    else
        brush.Color = Colors.Purple;
 
    return brush;
  }
}

The polygon is always purple.  I debugged the getter and the blue, red and purple are all being hit, so the property value is changing but the polygons are all one color on the screen.  
0
Andrey
Telerik team
answered on 26 Oct 2012, 11:56 AM
Hi Steve,

To get binding to work, your data model should implement INotifyPropertyChanged interface. The property you bind to (ForegroundColor) should send notification when its value changed (it is not implemented in your code).

Regards,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Map
Asked by
Steve
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or