我正在研究位置感知應用程序,我想要自定義圖釘有一個圖像,當您點擊圖像,添加標籤。我已經嘗試了幾個解決方案...如何用圖像,標籤和點擊事件創建自定義圖釘?
我開始使用此代碼,從這篇文章: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>
然後我試圖在一個包裹按鈕圖像,但剛纔的圖釘基本上看不見。然後我試圖使用控制模板,從我以前的應用程序之一,並且修改了它,並用此想出了:
<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>
還沒成爲贏家 - 我不能按鈕的內容綁定,因此文本塊。
會有一系列的圖釘,不同的圖片和不同的標籤,所以理想情況下,我想拿出一個我可以使用的模板,並從代碼中綁定圖片和標籤。按鈕的單擊事件的代碼將如同使文本塊可見或摺疊一樣簡單。
我知道我的第二個例子很醜,但我試圖讓視覺看起來很正確 - 我會根據視覺需要修改它,但是現在我需要弄清楚如何綁定圖像和代碼文本。按鈕點擊事件現在只用一個消息框(以顯示它註冊了點擊事件)。
感謝您的協助。
原諒我的經驗不足......這是作爲一個自定義控件來實現嗎?無論如何,你能否給我一個背後代碼實現的例子?或者我會從xaml做到這一點?我需要能夠控制顯示圖釘的哪個或哪些組,因爲它們將被分組。同時,我會盡力弄清楚。謝謝! – 2012-02-28 12:11:56
@霍普金斯,待命,我會看看能否在午餐時間爲你安排一些東西。 – KodeKreachor 2012-02-28 16:17:15
謝謝!我還在看。 – 2012-02-28 17:02:10