我的列表框與CollectionView Source綁定。當我更改過濾器時,它將自動選擇Listox中的第一個項目。在CollectionViewSource.Filter上的列表框中選擇第一個項目
App.ViewModel.TasksViewSource.Filter += new System.Windows.Data.FilterEventHandler(Tasks_Filter);
void Tasks_Filter(object sender, System.Windows.Data.FilterEventArgs e)
{
if (e.Item == null)
return;
Task task = e.Item as Task;
e.Accepted = task.Id.Equals(TaskId);
}
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (TasksListBox.SelectedIndex == -1)
return;
Task selectedTask = App.ViewModel.AllTasks[TasksListBox.SelectedIndex];
TasksListBox.SelectedIndex = -1;
NavigationService.Navigate(new Uri("/Views/TaskDetailsPage.xaml?taskId=" + selectedTask.Id, UriKind.Relative));
}
請幫幫我。