Silverlight – 通过C#向Bing Maps中的图钉添加文本

Silverlight – 通过C#向Bing Maps中的图钉添加文本,第1张

概述我能够使我的Silverlight Bing地图接受Mousclicks并将它们转换为C#中的Pushpins.现在我想在PushPin旁边显示一个文本作为鼠标越过引脚时出现的描述,我不知道如何做到这一点.有什么方法可以让我做这件事? 这是C#代码: public partial class MainPage : UserControl {     私人MapLayer m_PushpinLaye 我能够使我的Silverlight Bing地图接受Mousclicks并将它们转换为C#中的pushpins.现在我想在pushpin旁边显示一个文本作为鼠标越过引脚时出现的描述,我不知道如何做到这一点.有什么方法可以让我做这件事?

这是C#代码:

public partial class MainPage : UserControl

{
    私人MapLayer m_pushpinLayer;

public MainPage(){    InitializeComponent();    base.Loaded += OnLoaded;}private voID OnLoaded(object sender,RoutedEventArgs e){    base.Loaded -= OnLoaded;m_pushpinLayer = new MapLayer();x_Map.Children.Add(m_pushpinLayer);    x_Map.MouseClick += OnMouseClick;}private voID Addpushpin(double latitude,double longitude){    pushpin pushpin = new pushpin();    pushpin.MouseEnter += OnMouseEnter;    pushpin.MouseLeave += OnMouseLeave;    m_pushpinLayer.AddChild(pushpin,new Location(latitude,longitude),positionOrigin.BottomCenter);}private voID OnMouseClick(object sender,MapMouseEventArgs e){    Point clickLocation = e.VIEwportPoint;    Location location = x_Map.VIEwportPointTolocation(clickLocation);    Addpushpin(location.Latitude,location.Longitude);}private voID OnMouseLeave(object sender,MouseEventArgs e){    pushpin pushpin = sender as pushpin;    // remove the pushpin transform when mouse leaves    pushpin.Rendertransform = null;}private voID OnMouseEnter(object sender,MouseEventArgs e){    pushpin pushpin = sender as pushpin;    // scaling will shrink (less than 1) or enlarge (greater than 1) source element    Scaletransform st = new Scaletransform();    st.ScaleX = 1.4;    st.ScaleY = 1.4;    // set center of scaling to center of pushpin    st.CenterX = (pushpin as FrameworkElement).Height / 2;    st.CenterY = (pushpin as FrameworkElement).Height / 2;    pushpin.Rendertransform = st;}

}

解决方法 你有两种方法:

(1)创建任何UIElement以传递到pushpinLayer.AddChild. AddChild方法将接受任何UIElement,例如包含Image和TextBlock的GrID:

MapLayer m_pushpinLayer = new MapLayer(); Your_Map.Children.Add(m_pushpinLayer);Image image = new Image(); image.source = Resourcefile.GetBitmap("Images/pushpin.png",From.This); TextBlock textBlock = new TextBlock();textBlock.Text = "My pushpin";GrID grID = new GrID();grID.Children.Add(image);grID.Children.Add(textBlock);m_pushpinLayer.AddChild(grID,new Microsoft.Maps.MapControl.Location(42.658,-71.137),positionOrigin.Center);

(2)创建一个本机pushpin对象以传递到pushpinLayer.AddChild,但首先设置它的Template属性.请注意,pushpin是ContentControls,并且具有可以从XAML中定义的资源设置的Template属性:

MapLayer m_pushpinLayer = new MapLayer(); Your_Map.Children.Add(m_pushpinLayer); pushpin pushpin = new pushpin(); pushpin.Template = Application.Current.Resources["pushpinTemplate"]       as (ControlTemplate); m_pushpinLayer.AddChild(pushpin,positionOrigin.Center);

<ResourceDictionary     xmlns="http://schemas.microsoft.com/clIEnt/2007"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >     <ControlTemplate x:Key="pushpinTemplate">         <GrID>             <Image Source="Images/pushpin.png" />             <TextBlock Text="My pushpin" />         </GrID>     </ControlTemplate> </ResourceDictionary>

祝好运,
吉姆麦克库迪

面对面软件和YinYangMoney

总结

以上是内存溢出为你收集整理的Silverlight – 通过C#向Bing Maps中的图钉添加文本全部内容,希望文章能够帮你解决Silverlight – 通过C#向Bing Maps中的图钉添加文本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1005951.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存