Development and application of "Silverlight" Bing maps VI: Use style to beautify Pushpin (Pushpin) control

Source: Internet
Author: User
Tags addchild silverlight

Development and application of "Silverlight" Bing maps VI: Use style to beautify the ToolTip appearance of a Pushpin (Pushpin) control

In the Bing Maps development using the Bing Maps Silverlight control, pushpin (pushpin) annotation controls are used very frequently, and in most cases they use their ToolTip features to render some data information, but the default ToolTip appearance is not perfect, looks particularly ugly. In this need developers to achieve their own beautiful appearance of the interface, this article will take you into the tooltip of the pin (Pushpin) control of the road to beautify the appearance.

Before I wrote a custom Pushpin control and Information Tip panel article "Silverlight" Bing maps development Application and techniques two: custom Pushpin callout Control and dynamic Toolpanel, which details how to customize the push-pin control function. As well as its information presentation panel (Toolpanel), this article describes how to beautify the ToolTip appearance of the Pushpin controls built into Bing Maps Silverlight control with styles.

By default, you typically set the contents of its tooltip by using the following methods:

var pushpin = new Pushpin();
ToolTipService.SetToolTip(pushpin, "这里是图钉控件ToolTip内容!");
MapLayer.AddChild(pushpin, new Location(29.5076372217973, 106.489384971208));

The default tooltip looks very ugly, and developers can define styles to change other rendering effects, such as the following style code:

<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= "minheight=" >
<textblock text= "Here is the Pushpin control tooltip content!" "Fontsize=" foreground= "white"/>
</StackPanel>
</ContentPresenter.Content>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

So when you set the ToolTip of an object, you just need to dynamically refer to the style defined above for Tooptip, and you can invoke the custom style in the way that you do the following code.

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));

Its final operating effect is shown in the following illustration:

Note: This article is based on a simple translation of online articles, mainly for reference to realize the idea and added the relevant description, the original link is as follows:

Http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!1151.entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.