2013-11-29 32 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