I have a Listbox within my WP7 application, and inside the DataTemplate I have a toolkit:WrapPanel which then has a context menu (toolkit). How can I get the text of a textblock inside the listbox datatemplate when they click on the contextmenu menuitem?
Hope this makes sense heres some code:
<ListBox x:Name="FirstListBox" Margin="0,0,-12,0">
<ListBox.ItemTemplate>
<DataTemplate>
<toolkit:WrapPanel Margin="0,0,0,17" Width="432" Height="auto">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="copy" Click="copytoCB_Click"></toolkit:MenuItem>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding author}" TextAlignment="Left" TextWrapping="NoWrap" Style="{StaticResource PhoneTextExtraLargeStyle}" MinWidth="430" />
<TextBlock Text="{Binding content}" TextWrapping="Wrap" Name="txtContent" Style="{StaticResource PhoneTextSubtleStyle}"/>
</toolkit:WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Thanks,
Michael
Here you can see
WPF Commands
in action, maybe a good place to start. 🙂