Binding

5 posts, 0 answers
  1. Steve
    Steve avatar
    4 posts
    Member since:
    Oct 2012

    Posted 18 Oct 2012 Link to this post

    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>



  2. Steve
    Steve avatar
    4 posts
    Member since:
    Oct 2012

    Posted 18 Oct 2012 Link to this post

    Sorry, this should be in the Silverlight > Map section, not WPF > Map.  
  3. UI for WPF is Visual Studio 2017 Ready
  4. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 23 Oct 2012 Link to this post

    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.

  5. Steve
    Steve avatar
    4 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    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.  
  6. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 26 Oct 2012 Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready