private void fix(bool deleteDuplcates) { //Step 1: Swap listenedTimes table ids of deleted media files with the selected id MediaPlayerInfoUserControl goodFileToStay = getMediaPlayerInfoUserControl(lbxMediaUnits.SelectedItem); if (goodFileToStay == null) { MessageBox.Show("No good file selected or smth..."); return; } var duplicatesToDeleteIDs = new List <long>(); var duplicatesToDeleteCtrls = new List <MediaPlayerInfoUserControl>(); foreach (object lbxItem in lbxMediaUnits.Items) { MediaPlayerInfoUserControl mib = getMediaPlayerInfoUserControl(lbxItem); var l = mib.MediaUnitID; if (l != goodFileToStay.MediaUnitID) { duplicatesToDeleteIDs.Add(l); duplicatesToDeleteCtrls.Add(mib); } } _mediaInfoDbSrc.SmartCascadingDeleteOfAll(duplicatesToDeleteIDs, goodFileToStay.MediaUnitID); //Step 2: File.Delete the rest of the files if (deleteDuplcates == true) { foreach (MediaPlayerInfoUserControl mib in duplicatesToDeleteCtrls) { if (File.Exists(mib.PathFileName)) { mib.DeleteFS(mib.PathFileName); } } } //Step 3: Reload the list int idx = lbxMediaUnits.SelectedIndex; onFindMatches(null, null); lbxMediaUnits.SelectedIndex = idx; tbxFilterAnd.Focus(); }
MediaPlayerInfoUserControl getMediaPlayerInfoUserControl(object lbxItem) { //tu: Getting the currently selected ListBoxItem (ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/wpf_conceptual/html/bfcd564e-5e9e-451e-8641-a9b5c3cfac90.htm) //!!!: the ListBox must have IsSynchronizedWithCurrentItem set to True for this to work var listBoxItem = (ListBoxItem)(lbxMediaUnits.ItemContainerGenerator.ContainerFromItem(lbxItem)); //tu: ListBoxItem from bound data if (listBoxItem == null) { return(null); } ContentPresenter contentPresenter = FindVisualChild <ContentPresenter>(listBoxItem); DataTemplate myDataTemplate = contentPresenter.ContentTemplate; MediaPlayerInfoUserControl mpi = (MediaPlayerInfoUserControl)myDataTemplate.FindName("mpi", contentPresenter); return(mpi); }
private void setVolume(object lbxItem, double v) { // Getting the currently selected ListBoxItem (ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/wpf_conceptual/html/bfcd564e-5e9e-451e-8641-a9b5c3cfac90.htm) // Note that the ListBox must have IsSynchronizedWithCurrentItem set to True for this to work ListBoxItem listBoxItem = (ListBoxItem)(lbxMediaUnits.ItemContainerGenerator.ContainerFromItem(lbxItem)); if (listBoxItem == null) { return; } ContentPresenter contentPresenter = FindVisualChild <ContentPresenter>(listBoxItem); DataTemplate myDataTemplate = contentPresenter.ContentTemplate; MediaPlayerInfoUserControl mpi = (MediaPlayerInfoUserControl)myDataTemplate.FindName("mpi", contentPresenter); Slider sldVolume = (Slider)myDataTemplate.FindName("sldVolume", contentPresenter); mpi.Volume = v == 0 ? 0 : sldVolume == null ? 1 : sldVolume.Value; }