Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Silverlight-通过C向Bing地图中的图钉添加文本#_C#_.net_Silverlight_Bing Maps_Bing - Fatal编程技术网

C# Silverlight-通过C向Bing地图中的图钉添加文本#

C# Silverlight-通过C向Bing地图中的图钉添加文本#,c#,.net,silverlight,bing-maps,bing,C#,.net,Silverlight,Bing Maps,Bing,我能够让我的silverlight Bing地图接受鼠标点击,并将它们转换为C#中的图钉。现在我想在图钉旁边显示一个文本,作为鼠标在图钉上移动时出现的描述,我不知道该如何做。有什么方法可以让我做这件事 这是C代码: { 私有映射层m_PushpinLayer public MainPage() { InitializeComponent(); base.Loaded += OnLoaded; } private void OnLoaded(object sender, Rout

我能够让我的silverlight Bing地图接受鼠标点击,并将它们转换为C#中的图钉。现在我想在图钉旁边显示一个文本,作为鼠标在图钉上移动时出现的描述,我不知道该如何做。有什么方法可以让我做这件事

这是C代码:

{ 私有映射层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) 创建任何要传递到PushPinLayer.AddChild的UIElement。AddChild方法将接受和任何UIElement,例如包含图像和文本块的网格:

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) 创建本机图钉对象以传递到PushpinLayer.AddChild,但首先设置其模板属性。请注意,图钉是ContentControls,具有可从XAML中定义的资源设置的模板属性:

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, 
    new Microsoft.Maps.MapControl.Location(42.658, -71.137),   
        PositionOrigin.Center);


祝你好运, 吉姆·麦考迪


面对面软件,还有阴阳钱

谢谢吉姆。。这很有帮助:)一开始它不起作用。。直到我更改了网格。添加到网格。子项。添加。。。再次感谢!
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, 
    new Microsoft.Maps.MapControl.Location(42.658, -71.137),   
        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>