for example, i have a simple database (int id, string text) and listbox.
in each listbox element i have a textblock, image and button.
when I add items I want each item listobox was known as the id.
When I click the button, the id is passed in another form in which I can edit the database post.
page.xaml
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Image Source="{Binding IconSource}"/>
<StackPanel>
<TextBlock Text="{Binding Text}"/>
<Button Click="Edit_Click1"></Button>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
page.xaml.cs
private void Edit_Click1(object sender, RoutedEventArgs e)
{
int id = 0; // i want to know id of current element of listbox
NavigationService.Navigate(new Uri("/EditTask.xaml?currentID="+id, UriKind.Relative));
}
how i can name current item of listbox and then know name of this element? sorry for horrible english.
You can access the
listbox.SelectedItemto get the selected item: