Hello All,I created a template control for map tip as:Map Tip Template XAML:<Style TargetType="local:MapTipTemplate">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MapTipTemplate">
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="DisplayInfoBtn" Content="Info Window" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" Width="89" />
<Button x:Name="TestBtn" Content="Button" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="95,0,0,0" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Code Behind:public class MapTipTemplate : Control
{
private ButtonBase _displayInfoBtn;
public MapTipTemplate()
{
this.DefaultStyleKey = typeof(MapTipTemplate);
}
/// <summary>
/// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate"/>. In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks.
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_displayInfoBtn = GetTemplateChild("DisplayInfoBtn") as ButtonBase;
if (null != _displayInfoBtn)
_displayInfoBtn.Click += button1_Click;
}
public InfoWindow Window
{
get { return (InfoWindow)GetValue(WindowProperty); }
set { SetValue(WindowProperty, value); }
}
/// <summary>
/// Backing store for <see cref="InfoWindow"/> property.
/// </summary>
public static readonly DependencyProperty WindowProperty =
DependencyProperty.Register("Window", typeof(InfoWindow), typeof(MapTipTemplate), null);
/// <summary>
/// Gets or sets the id of the parent layer.
/// </summary>
/// <value>
/// The id of the layer.
/// </value>
public string LayerId
{
get { return (string)GetValue(LayerIdProperty); }
set { SetValue(LayerIdProperty, value); }
}
/// <summary>
/// Backing store for <see cref="LayerId"/> property.
/// </summary>
public static readonly DependencyProperty LayerIdProperty =
DependencyProperty.Register("LayerId", typeof(string), typeof(MapTipTemplate), null);
private void button1_Click(object sender, RoutedEventArgs e)
{
//close other map tip popup
var popup = Parent as Popup;
if (null != popup)
popup.IsOpen = false;
if (Window == null)
return;
Window.Anchor = Helper.mapPoint;
Window.IsOpen = true;
}
}
I used the map tip in the MainPage.xaml as: <esri:Map x:Name="Map" Background="White" MouseMove="Map_MouseMove">
<esri:ArcGISTiledMapServiceLayer ID="BaseLayer"
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
<esri:FeatureLayer ID="FeatureLayer"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"
Where="POP1990 > 100000">
<esri:FeatureLayer.MapTip>
<Bug:MapTipTemplate LayerId="FeatureLayer" esri:GraphicsLayer.MapTipHideDelay="0:0:0.7" Window="{Binding ElementName=MyInfoWindow}" />
</esri:FeatureLayer.MapTip>
</esri:FeatureLayer>
<esri:FeatureLayer ID="FeatureLayer1"
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/1">
<esri:FeatureLayer.MapTip>
<Bug:MapTipTemplate LayerId="FeatureLayer1" esri:GraphicsLayer.MapTipHideDelay="0:0:0.7" Window="{Binding ElementName=MyInfoWindow}" />
</esri:FeatureLayer.MapTip>
</esri:FeatureLayer>
</esri:Map>
<esri:InfoWindow x:Name="MyInfoWindow"
Padding="2"
CornerRadius="20"
Background="LightSalmon"
Map="{Binding ElementName=Map}"
ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}" />
The Map Tip in the feature layer uses the ElementName binding to bind the Dependency Property "Window" to the InfoWindow defined in Xaml.Basically the Map Tip shows a button which upon clicking is supposed to display a Info Window. This works if you hover the mouse over any of the two features first and click the map tip button. However if you hover the mouse to the other feature, the map tip is displayed but upon clicking the button the Info Windows does not show up. Upon debugging, I found out that Window property is null. I tried to debug the Binding installing the Silverlight 5 beta and found out that I am getting following error:{Error: System.Exception: BindingExpression_CannotFindElementName}
Note:Binding works for any of the feature layers I hover over first but does not work for the other feature. I have created a User Control - "CustomMapTip" as well which is equivalent to the map tip template control. If I use the user control instead of the template control, everything works fine. This can be verified by changing the control from MapTipTemplate to the CustomMapTip in the MainPage.xaml of the project attached.Any idea on what's wrong with the implementation?I have attached the complete silverlight solution herewith.