2010-05-10 15 views
5

के माध्यम से बिंग मैप्स में पुशपिन में टेक्स्ट जोड़ना मैं अपनी चांदी की रोशनी बनाने में सक्षम था बिंग नक्शा मूसक्लिक स्वीकार करता है और उन्हें सी # में पुष्पिन में परिवर्तित करता है। अब मैं पुशपिन के बगल में एक टेक्स्ट दिखाना चाहता हूं जो वर्णन करता है कि जब माउस पिन पर जाता है, तो मुझे कोई संकेत नहीं है कि यह कैसे करें। ऐसी चीजें हैं जो मुझे यह करने में सक्षम बनाती हैं?सिल्वरलाइट - सी #

यह सी # कोड है:

public partial class MainPage : UserControl 

{ निजी MapLayer m_PushpinLayer;

(1) PushPinLayer.AddChild में पारित करने के लिए किसी भी UIElement बनाएँ:

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

}

उत्तर

7

आप जाने के लिए 2 तरीके हैं। AddChild विधि इस ग्रिड एक छवि और एक TextBlock युक्त रूप में किसी भी 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); 

...

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

गुड लक, जिम McCurdy

चेहरा सॉफ्टवेयर का सामना करने के लिए, और YinYangMoney

+0

धन्यवाद जिम .. यह बहुत उपयोगी था :) यह पहले काम नहीं करता .. जब तक मैंने ग्रिड नहीं बदला। ग्रिड में जोड़ें। चिल्ड्रे एन। जोड़ें ... फिर से धन्यवाद! – Morano88