在使用Bing Maps Silverlight Control进行Bing Maps开发中,图钉(Pushpin)标注控件的使用频率是非常之高,多数情况下都会使用其ToolTip特性来呈现一些数据信息,但默认的ToolTip外观并不xx,显得格外的难看。于此需要开发者自己实现其漂亮的外观界面,本篇将由浅入深的带你走入图钉(Pushpin)控件的ToolTip外观美化之路。
var pushpin = new Pushpin();
ToolTipService.SetToolTip(pushpin, "这里是图钉控件ToolTip内容!");
MapLayer.AddChild(pushpin, new Location(29.5076372217973, 106.489384971208));
<Style x:Key="PushpinStyle" TargetType="ToolTip">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border CornerRadius="5">
<Border.Background>
<SolidColorBrush Color="Black" Opacity="0.5"/>
</Border.Background>
<ContentPresenter Margin="5">
<ContentPresenter.Content>
<StackPanel Margin="5" MaxWidth="200" MinHeight="80">
<TextBlock Text="这里是图钉控件ToolTip内容!" FontSize="12" Foreground="White"/>
</StackPanel>
</ContentPresenter.Content>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
var pushpin = new Pushpin();
ToolTipService.SetToolTip(pushpin, new ToolTip()
{
Style = Application.Current.Resources["PushpinStyle"] as Style
});
MapLayer.AddChild(pushpin, new Location(29.5076372217973, 106.489384971208));