Hello! There is a button created inside the ListView through the Template:
<GridViewColumn Width="80" Header="Скачать"> <GridViewColumn.CellTemplate> <DataTemplate> <Button Name="DownloadBtn" Click="Button_Click" Content="Скачать" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn>
It is necessary to make it so that when you click on it, the entire ListView row is selected.
In general, the program should download an item by reference from the collection bound to the ListView, and for this I need to get SelectedIndex from the ListView (or in some other way?).
Just in case, the code from ButtonClick:
private void Button_Click(object sender, RoutedEventArgs e) { using (var client = new System.Net.WebClient()) { client.DownloadFileAsync( MainViewModel.ModelMainWindow.SongsPlaylist[ MainViewModel.ModelMainWindow.OneClickIndex].SongUri, "D:\\" + MainViewModel.ModelMainWindow.SongsPlaylist[ MainViewModel.ModelMainWindow.OneClickIndex].Artist + " - " + MainViewModel.ModelMainWindow.SongsPlaylist[ MainViewModel.ModelMainWindow.OneClickIndex].Title + ".mp3"); } }
DataContext
ofButton
have a collection item like?(sender as Button).DataContext
- Dmitry Chistik