I need to add on a BingMap control one or more pushpins with custom static image and text, which is set in code. Here is my pushpin template:
<ControlTemplate x:Key="PushpinTemplate" TargetType="maps:Pushpin">
<Grid x:Name="ContentGrid"
Width="39"
Height="48">
<Image Source="Images/pin.png" Stretch="None"/>
<TextBlock Text="Text" />
</Grid>
</ControlTemplate>
How to make property TextBlock.Text can be changed programmatically? Say bind it to a property Pushpin.Content. Thanks.
Solved by dynamic generation of control template.
private ControlTemplate CreateTemplate(string image, string text)
{
string xaml = "<ControlTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:maps=\"clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps\" TargetType=\"maps:Pushpin\"><Grid x:Name=\"ContentGrid\" Width=\"39\" Height=\"48\"><Image Source=\"" + image + "\" Stretch=\"None\"/><TextBlock Margin=\"14,2,0,0\" FontSize=\"20\" Text=\"" + text + "\" /></Grid></ControlTemplate>";
ControlTemplate сt = (ControlTemplate)XamlReader.Load(xaml);
return сt;
}