public MainWindow() { InitializeComponent(); DataContext = Context; DispatcherTimer timer = new DispatcherTimer { Interval = Properties.Settings.Default.TickInterval }; timer.Tick += (ts, te) => { var element = PlayersItemsControl.ItemContainerGenerator.ContainerFromItem(Context.CurrentPlayer) as FrameworkElement; var mediaPlayer = VisualTreeHelper.GetChild(element, 0) as MediaElement; if (mediaPlayer.Source == null || isNextTriggered || mediaPlayer.NaturalDuration.HasTimeSpan && mediaPlayer.Position >= mediaPlayer.NaturalDuration.TimeSpan - Properties.Settings.Default.CrossFadingInterval) { isNextTriggered = false; var playableSongs = Context.AvailableSongs.Where(s => s.IsPlayable).ToArray(); if (playableSongs.Length > 0) { var random = new Random(); var song = playableSongs[random.Next(playableSongs.Length)]; Context.Play(song); AvailableSongsListBox.ScrollIntoView(song); AvailableSongsListBox.SelectedItem = song; } } }; timer.Start(); SearchTextBox.Focus(); }
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) { AvailableSongsListBox.SelectedItem = Context.AvailableSongs.FirstOrDefault(s => s.ToString().ToLower().Contains(SearchTextBox.Text.ToLower())); if (AvailableSongsListBox.SelectedItem != null) { AvailableSongsListBox.ScrollIntoView(AvailableSongsListBox.SelectedItem); } }