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

Programmtically changing MapShapeReader Tooltip when using a custom template

3 Answers 132 Views
Map
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 22 Nov 2010, 06:25 PM
    <DataTemplate x:Key="CustomToolTipDataTemplate2" x:Name="toolTipTemplate2">
        <StackPanel Margin="10,5">
            <TextBlock FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="12" Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='NAME', StringFormat=County: {0}}" />
            <TextBlock x:Name="KPITip" FontFamily="Trebuchet MS" FontSize="12" Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='PAT_EST', StringFormat='Percentage of Paternity Established: {0:0.##}'}" />
        </StackPanel>
    </DataTemplate>
</Grid.Resources>


How can I programmatically change the ConvertParameter in those TextBlocks and also change the Colorizer ExtendedPropertyName? I can't seem to figure out how to get to them.

3 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 25 Nov 2010, 04:04 PM
Hello James,

If I quite understand your goals you want to change dynamically extended property which is used to show information in the tooltip when all shapes are loaded already. Unfortunately you can’t do it. The ConverterParameter property of the Binding class is not a DependencyProperty, so you can’t use dynamic resource or binding in this place. But you can re-create the tooltip template from code and then apply it to the loaded shapes. Prospective code could looks like the following:

private DataTemplate CreateTooltipTemplate(string propertyName)
{
    string textBinding1 =
        "{Binding Converter={StaticResource ExtendedDataConverter},"
        + "ConverterParameter='"
        + propertyName
        + "', StringFormat=State: {0}}";
  
    string textBinding2 =
        "{Binding Converter={StaticResource ExtendedDataConverter},"
        + "ConverterParameter='Population',"
        + " StringFormat=Population: {0:F0}}";
  
    XNamespace telerik = "http://schemas.telerik.com/2008/xaml/presentation";
  
    XElement dataTemplateElement = new XElement("DataTemplate",
        new XElement("StackPanel",
            new XAttribute("Margin", "10,5"),
            new XElement("StackPanel.Resources",
                new XElement(telerik + "ExtendedDataConverter",
                    new XAttribute(xns + "Key", "ExtendedDataConverter"))),
            new XElement("TextBlock",
                new XAttribute("FontWeight", "Bold"),
                new XAttribute("FontFamily", "Trebuchet MS"),
                new XAttribute("FontSize", "12"),
                new XAttribute("Text", textBinding1)),
            new XElement("TextBlock",
                new XAttribute("FontWeight", "Bold"),
                new XAttribute("FontFamily", "Trebuchet MS"),
                new XAttribute("FontSize", "12"),
                new XAttribute("Text", textBinding2))));
  
    string dataTemplateXaml = dataTemplateElement.ToString();
    MemoryStream sr = new MemoryStream(Encoding.ASCII.GetBytes(dataTemplateXaml)); ;
          
    ParserContext pc = new ParserContext();
    pc.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
    pc.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
    pc.XmlnsDictionary.Add("telerik", "http://schemas.telerik.com/2008/xaml/presentation");
  
    DataTemplate dataTemplate = (DataTemplate)XamlReader.Load(sr, pc);
  
    return dataTemplate;
}
  
  
private void SetTooltipToShapes()
{
    DataTemplate tooltipTemplate = this.CreateTooltipTemplate("YEARADM");
    foreach (object item in this.informationLayer.Items)
    {
        MapShape shape = item as MapShape;
        if (shape != null)
        {
            ToolTip toolTip = new ToolTip();
            toolTip.Content = shape.ExtendedData;
            toolTip.ContentTemplate = tooltipTemplate;
            ToolTipService.SetToolTip(shape, toolTip);
        }
    }
}

I hope this gets you started properly.

Greetings,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Rebecca
Top achievements
Rank 1
answered on 27 Apr 2011, 01:28 AM
Hello,

I have a similar goal where I want to suppliment the DBF information for a shapefile with information from a WCF RIA service.  I want to use LotNumber for the key/index in the dbf and the RIA service.  Then I want to include fields from the RIA service in the ToolTip dataTemplate for each shape in the shapefile.  Do you have an example of how this would be done?  I've largely worked with my Ria Service in the XAML rather than the C# Code Behind.

Here's the field I want to bind from my RIA service:

 

 

 

<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:cTx, CreateList=true}" Height="0" LoadedData="centralTxDomainDataSource_LoadedData" Name="centralTxDomainDataSource" QueryName="GetCTxesQuery" Width="0">

 

 

 

 

<riaControls:DomainDataSource.DomainContext>

 

 

 

 

<my:cTxDomainContext />

 

 

 

 

</riaControls:DomainDataSource.DomainContext>

 

 

 

 

</riaControls:DomainDataSource>

 

 

<

 

 

TextBox Grid.Column="1" Grid.Row="0" Height="23" HorizontalAlignment="Left" Margin="3" Name="addressTextBox" Text="{Binding Path=address, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Top" Width="120" />

 

 

 

 

 

 

 

 

 


Thanks,
Rebecca

0
Andrey
Telerik team
answered on 29 Apr 2011, 11:24 AM
Hi Rebecca,

Unfortunately we don't have an example which reads additional info using RIA service. I think I can suggest the following way to include fields from the RIA service in the ToolTip dataTemplate:
1. Create the TooltipConverter class which inherits the IValueConverter interface.
2. Use it with binding in the tooltip template.
3. When the data from the RIA service is loaded then you can add it to a dictionary class instance.
   The dictionary should be like to the following: Dictionary<string, MyTable>
   When you will add data to it then the LotNumber field should be used as a key for the dictionary.
4. When the tooltip is requested then the Convert method of the TooltipConverter class should get the LotNumber value from the ExtendedData instance.
   It will be available as the value parameter of the Convert method.
   So, you can retrive information for tooltip from any field of your table from the dictionary.

The sample code is below. I hope this gets you started.

<UserControl x:Class="RIATest.MainPage"
    xmlns:local="clr-namespace:RIATest"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <local:TooltipConverter x:Key="converter" />
        <DataTemplate x:Key="toolTipTemplate">
            <TextBlock Text="{Binding Converter={StaticResource converter}}" />
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadMap x:Name="radMap"
                        Center="40,-100"
                        ZoomLevel="3">
            <telerik:RadMap.Provider>
                <telerik:OpenStreetMapProvider />
            </telerik:RadMap.Provider>
            <telerik:InformationLayer x:Name="informationLayer">
                <telerik:InformationLayer.Reader>
                    <telerik:MapShapeReader Source="usa_st"
                                            ToolTipTemplate="{StaticResource toolTipTemplate}" />
                </telerik:InformationLayer.Reader>
            </telerik:InformationLayer>
        </telerik:RadMap>
    </Grid>
</UserControl>
private void loadOp_Completed(object sender, EventArgs e)
{
    TooltipConverter.DataDictionary = new Dictionary<string, MyTable>();
    var loadOp = sender as LoadOperation<MyTable>;
    foreach (var entity in loadOp.Entities)
    {
        TooltipConverter.DataDictionary.Add(entity.LotNumber, entity);
    }
}
public class TooltipConverter : IValueConverter
{
    public static Dictionary<string, MyTable> DataDictionary
    {
        get;
        set;
    }
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var data = value as ExtendedData;
        var lotNumber = (string)data.GetValue("LotNumber");
        if (DataDictionary != null
            && DataDictionary.ContainsKey(lotNumber))
        {
            return DataDictionary[lotNumber].MyTooltipField;
        }

        
return null;
    }

    
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Greetings,
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
Tags
Map
Asked by
James
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Rebecca
Top achievements
Rank 1
Share this question
or