2013-11-29 72 views
1

我有一個風格圖釘綁定圖釘風格文本PushPin.Text

<Style x:Key="PushPinStyle" TargetType="Maps:Pushpin"> 
     <Setter Property="Width" Value="25"/> 
     <Setter Property="Height" Value="39"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Grid>      
       <Image Source="Assets/Point.png" Stretch="Uniform" HorizontalAlignment="Left"/> 
        <TextBlock Text={Binding Text}/> 
         </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

而且我想文本塊綁定到pushpin.text

public void AddPushpin(Location latlong, string title, string description, MapLayer layer,string pinText) 
    { 
     try 
     { 
      Pushpin p = new Pushpin() 
       { 
        Tag = new Metadata() 
        { 
         Title = title, 
         Description = description 
        } 
       }; 
     // 
      p.Style =  this.Resources["PushPinStyle"] as Style; 
      p.Text = pinText;      //This should appear in pushpin on top of Image 

      MapLayer.SetPosition(p, latlong); 

      p.Tapped += PinTapped; 

      layer.Children.Add(p); 
     } 
     catch (Exception ex) 
     { 


     } 
    } 

但所有我只能看到是形象。

如何將PushPin.text綁定到樣式的TextBlock並將其顯示在樣式的圖像上方?

回答

1

您可以使用二者之一。

<Style x:Key="PushPinStyle" TargetType="Maps:Pushpin"> 
    <Setter Property="Width" Value="25"/> 
    <Setter Property="Height" Value="39"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="Maps:Pushpin"> 
       <Grid> 
        <Image Source="Assets/Point.png" Stretch="Uniform" HorizontalAlignment="Left"/> 
        <TextBlock Text="{TemplateBinding Text}"/> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

OR

<TextBlock Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}"/> 
+0

文本不{TemplateBinding文字}辨認,沒有工作 – uncia

+0

退房更新的解決方案。 – Xyroid