I am working on a location aware app, where I want to have custom pushpins that have an image, and when you tap the image, a label is added. I have tried a couple of solutions...
I started with this code, from this article: http://igrali.wordpress.com/2011/12/06/making-a-custom-windows-phone-bing-pushpin-from-an-image/
<ControlTemplate
x:Key="PushpinMe"
TargetType="maps:Pushpin">
<Grid
Name="PushpinMeGrid"
Height="50"
Width="50"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Image
x:Name="PushpinMeImage"
Height="50"
Width="50"
Source="Pushpins/pushpinSeaplane.png" />
<TextBlock Text="{Binding Source=}"
</Grid>
</ControlTemplate>
Then I tried wrapping the image in a button, but that just made the pushpin essentially invisible. Then I tried using a control template from one of my prior apps, and modified it, and came up with this:
<Button
Name="PushpinButton"
Click="Button_Click">
<Button.Style>
<Style
TargetType="Button">
<Setter
Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="Button">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
<Image
Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="2"
Height="50"
Width="50"
Source="Pushpins/pushpinSeaplane.png" />
<Grid
Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition
Height="39" />
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<Grid
Grid.Row="0"
Background="Black">
<TextBlock
Grid.Row="0"
Foreground="White"
Text="{Binding ElementName=me,
Path=Content}"
TextWrapping="Wrap"
Margin="5" />
</Grid>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</ControlTemplate>
Still not a winner - I can't bind the content of the button, and therefore the textblock.
There will be a series of pushpins, with different images, and different labels, so ideally, I would like to come up with a template that I can use, and bind the image and the label from code. The code for the button's click event would be as simple as making the textblock visible or collapsed.
I know my second example is pretty ugly, but I was trying to make the visual look right - I'll modify it as needed for the visuals, but for the moment, I need to figure out how I can bind the image and the text from code. The button click event works with just a messagebox for now (to show that it registered the click event).
Thanks for your assistance.