//---------------------------------------------------------------------------------------------------------------------- private void TcList_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { return; tcList.ApplyTemplate(); DataTemplate myDataTemplate = tcList.ContentTemplate; ContentPresenter contentPresenter = FindVisualChild <ContentPresenter>(tcList); try { DataGrid dg = myDataTemplate.FindName("dbTracks", contentPresenter) as DataGrid; IPlayerActionQueriable playerAction = DataContext as IPlayerActionQueriable; if (dg != null && playerAction != null) { int idx = playerAction.TrackByList(dg.DataContext); if (idx >= 0) { dg.ScrollIntoView(dg.Items[idx]); dg.SelectedIndex = idx; //dg.SelectedItems.Clear(); //dg.SelectedItems.Add(item); } } } catch { } }
//------------------------------------------------------------------------------------------------------------------- private void ScrollIntoView() { tcList.ApplyTemplate(); DataTemplate myDataTemplate = tcList.ContentTemplate; ContentPresenter contentPresenter = FindVisualChild <ContentPresenter>(tcList); try { DataGrid dg = myDataTemplate.FindName("dbTracks", contentPresenter) as DataGrid; IPlayerActionQueriable playerAction = DataContext as IPlayerActionQueriable; if (dg != null && playerAction != null) { int idx = playerAction.TrackByList(dg.DataContext); if (idx >= 0) { dg.ScrollIntoView(dg.Items[idx]); dg.SelectedIndex = idx; Keyboard.Focus(dg); // ContentPresenter cp = dg.ItemContainerGenerator.ContainerFromItem(dg.Items[idx]) as ContentPresenter; //// TextBox tb = FindVisualChild<TextBox>(cp); // TextBlock tb = dg.ItemTemplate.FindName("tbFileName", cp) as TextBlock; // if (tb != null) // { // // do something with tb // } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
//---------------------------------------------------------------------------------------------------------------------- private void Window_Loaded_1(object sender, RoutedEventArgs e) { var viewModel = new PlayerViewModel(); DataContext = viewModel; IPlayerActionQueriable playerAction = DataContext as IPlayerActionQueriable; if (playerAction != null) { playerAction.PlayQuery += Play; playerAction.PauseQuery += Pause; playerAction.StopQuery += Stop; playerAction.ListChangeQuery += PlayerActionOnListChangeQuery; playerAction.FolderDialogQuery += playerAction_FolderDialogQuery; playerAction.ChangePathDialogQuery += playerAction_ChangePathDialogQuery; } ISavable saveModel = DataContext as ISavable; if (saveModel != null) { this.Closing += (s, ev) => saveModel.Save();; } // workPlayer.Stretch = Stretch.; workPlayer.StretchDirection = StretchDirection.Both; Binding bindingCurrentTrackDeletePressCommand = new Binding("CurrentTrackDeletePressCommand"); bindingCurrentTrackDeletePressCommand.Source = DataContext; BindingOperations.SetBinding(this, PlayerWindow.CurrentTrackDeletePressCommandProperty, bindingCurrentTrackDeletePressCommand); Binding bindingCurrentTrackDoubleClickCommand = new Binding("CurrentTrackDoubleClickCommand"); bindingCurrentTrackDoubleClickCommand.Source = DataContext; BindingOperations.SetBinding(this, PlayerWindow.CurrentTrackDoubleClickCommandProperty, bindingCurrentTrackDoubleClickCommand); IScrollIntoViewAction scrollIntoViewAction = (IScrollIntoViewAction)DataContext; scrollIntoViewAction.MainGridScrollIntoView += i => { ScrollIntoView(); }; playerAction.OnLoad(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(500); timer.Tick += timer_Tick; timer.Start(); }