Update Tooltip after changing ExtendedData.

4 posts, 1 answers
  1. kris
    kris avatar
    5 posts
    Member since:
    Apr 2011

    Posted 04 May 2011 Link to this post

    I have created us state map and bind it with slider. States change color based on slider value. Code is working but tooltip values are not changing. Please advise?

    <Grid.Resources>
                <telerik:ExtendedDataConverter x:Key="ExtendedDataConverter" />
                <DataTemplate x:Key="CustomToolTipDataTemplate">
                    <StackPanel Margin="10,5">
                        <TextBlock FontWeight="Bold" Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='NAME'}" />
                        <TextBlock Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='UnemployedNo', StringFormat='Unemployment: {0:#,#.0} k.'}" />
                    </StackPanel>
                </DataTemplate>
            </Grid.Resources>
            <telerik:RadMap Name="radMap1" ZoomLevel="4"
                            Center="37.684297,-95.06924"
                            UseDefaultLayout="False"
                            MouseDragMode="Drag"
                            MouseClickMode="None"
                            MouseDoubleClickMode="None"
                            IsMouseWheelZoomEnabled="True"
                            IsKeyboardNavigationEnabled="False" InitializeCompleted="radMap1_InitializeCompleted">
                <telerik:RadMap.Provider>
                    <telerik:EmptyProvider />
                </telerik:RadMap.Provider>
                <telerik:InformationLayer x:Name="StateLayer">
                    <telerik:InformationLayer.Reader>
                        <telerik:MapShapeReader/>
                    </telerik:InformationLayer.Reader>
                    <telerik:InformationLayer.Colorizer>
                        <telerik:ColorMeasureScale Mode="Count" TickMarkCount="7">
                            <telerik:ColorMeasureScale.ShapeFillCollection>
                                <telerik:MapShapeFill Fill="#FFF0D9" Stroke="#B1946D" StrokeThickness="1" />
                                <telerik:MapShapeFill Fill="#FFE4BA" Stroke="#B1946D" StrokeThickness="1" />
                                <telerik:MapShapeFill Fill="#FFDBA3" Stroke="#B1946D" StrokeThickness="1" />
                                <telerik:MapShapeFill Fill="#FFD28D" Stroke="#B1946D" StrokeThickness="1" />
                                <telerik:MapShapeFill Fill="#FFBF5C" Stroke="#B1946D" StrokeThickness="1" />
                                <telerik:MapShapeFill Fill="#FFAF33" Stroke="#B1946D" StrokeThickness="1" />
                                <telerik:MapShapeFill Fill="#E2942D" Stroke="#B1946D" StrokeThickness="1" />
                            </telerik:ColorMeasureScale.ShapeFillCollection>
                            <telerik:ColorMeasureScale.HighlightFillCollection>
                                <telerik:MapShapeFill Fill="#FFEEA6" Stroke="#B1946D" StrokeThickness="1" />
                            </telerik:ColorMeasureScale.HighlightFillCollection>
                        </telerik:ColorMeasureScale>
                    </telerik:InformationLayer.Colorizer>
                </telerik:InformationLayer>
            </telerik:RadMap>
            <telerik:RadSlider x:Name="dateSlider" TickFrequency="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
        </Grid>

    void dateSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            int val = (int)e.NewValue;
            foreach (var item in StateRecordList)
                item.BindShapeByDateRank(val);
            SetStateColorizer(StateRecordList.Select(x=>x.StateShape).Cast<FrameworkElement>().ToList());
        }
    public void BindShapeByDateRank(int dataRank)
            {
                var record = MapValues.Where(x => x.DateRank == dataRank).FirstOrDefault();
                if (record.DateRank == dataRank)
                {
                    StateShape.ExtendedData.SetValue(UnemployedNoPropertyName, record.UnemployedNo);
                }
            }
    private void SetStateColorizer(List<FrameworkElement> list)
        {
            var colorizer = this.StateLayer.Colorizer as ColorMeasureScale;
            colorizer.MinValue = MinColorizerValue;
            colorizer.MaxValue = MaxColorizerValue;
            colorizer.ExtendedPropertyName = UnemployedNoPropertyName;
            colorizer.SetColorByExtendedData(list, UnemployedNoPropertyName, true);
        }
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 10 May 2011 Link to this post

    Hello Kris,

    The current implementation of the ExtendData supports a kind of the 'one-time' binding only. The tooltips or other framework elements don't change properties when binded extended data is changed. We are planning to change it in the future releases. You can check availability of this feature using our PITS:

    http://www.telerik.com/support/pits.aspx#/public/silverlight/5876

    There is a workaround you can use with current version of the RadMap:
     
    1. You should create wrapper class for the extended data:

    public class ExtendedDataWraper : INotifyPropertyChanged
    {
        private ExtendedData data;
      
        /// <summary>
        /// Occurs when property changed. Implemented for binding.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
      
        public ExtendedData Data
        {
            get
            {
                return this.data;
            }
      
            set
            {
                this.data = value;
                this.data.PropertyChanged += new PropertyChangedEventHandler(data_PropertyChanged);
                this.OnPropertyChanged("Data");
            }
        }
      
        private void data_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.OnPropertyChanged("Data");
        }
      
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChangedEventArgs eventArgs = new PropertyChangedEventArgs(
                    propertyName);
                this.PropertyChanged(this, eventArgs);
            }
        }
    }

    2. You should change tooltip data template as following:

    <DataTemplate x:Key="CustomToolTipDataTemplate">
        <StackPanel Margin="10,5">
            <TextBlock FontWeight="Bold" 
                Text="{Binding Path=Data,Converter={StaticResource ExtendedDataConverter}, ConverterParameter='NAME'}" />
            <TextBlock Text="{Binding Path=Data,Converter={StaticResource ExtendedDataConverter}, ConverterParameter='UnemployedNo', StringFormat='Unemployment: {0:#,#.0} k.'}" />
        </StackPanel>
    </DataTemplate>

    The major change is in the binding settings. Path=Data is in use.

    3. You should set tooltip to map shape objects in the Reader.PreviewReadCompleted event handler as following:

    MapShape polygon = item as MapShape;
    if (polygon != null)
    {
        // Setup tooltip for shape.
        ToolTip toolTip = new ToolTip();
        toolTip.Content = new ExtendedDataWraper() { ExtendedData = data };
        toolTip.ContentTemplate = this.Resources["CustomToolTipDataTemplate"] as DataTemplate;
        ToolTipService.SetToolTip(polygon, toolTip);
    }


    Best wishes,
    Andrey Murzov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. PETE
    PETE avatar
    2 posts
    Member since:
    Sep 2007

    Posted 14 May 2013 Link to this post

    The status of issue 5876 is "resolved". The issue is a feature request. From the Issue Tracker help page, it is not clear to me what resolved status means for a feature request. What does it mean to be resolved status? Was the feature implemented in RadControls?
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 15 May 2013 Link to this post

    Hello Pete,

    For the feature request "Resolved" means that feature is implemented already.

    Kind regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top