I’m writting a Windows Phone App, in the GUI a have a listbox with many buttons, something like this
<ListBox x:Name="List">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="460" Height="100" Click="Click_B">
<Button.Content>
<StackPanel Orientation="Horizontal" Height="80" Width="400">
<TextBlock Width="200" Name="txtblockName" FontSize="22" Text="{Binding Name}" Height="40"/>
<TextBlock Width="200" Name="txtblockUrl" FontSize="22" Text="{Binding Url}" Height="40"/>
</StackPanel>
</Button.Content>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I need to obtain the content of the TextBlock “txtblockUrl” when I click on the Button, how can I obtain this value ?
private void Click_B(object sender, RoutedEventArgs e)
{
Button source = (Button)e.OriginalSource;
}
You can walk down the layout hierarchy as shown below
However, data binding a list of objects to your
ListBox.ItemsSourceis a better solution than this.