我有PushPin的风格
<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>
我希望textblock绑定到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并将其显示在样式图像上方?
答案 0 :(得分: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}}"/>