0

我有一个绑定到服务的列表框。它加载得很好,允许我选择一个项目并移动到第二页。

第二页从同一个服务加载一个新的 observable 集合,并使用从前一页中选择的项目来加载一个带有数据过滤器的新列表框。

第二个列表框允许进一步选择以基于此选择加载详细信息页面。我遇到的错误是第二个列表框加载并自动选择列表中的第一项。按下后退按钮后,它会加载第二个列表框而不进行任何选择。

有人可以告诉我如何停止第二个列表框中的自动选择吗?代码详情如下。

第一个列表框代码,包括发件人

void ServiceReference1Client_GetMensleaderListCompleted(object sender, GetMensLeaderListCompletedEventArgs e)
    {
        if (e.Error != null) { MensHeading.Text = "Connect to Data"; return; }

        ObservableCollection<Mens_Leaders> mensLeaders = e.Result;

        this.mensRankings.ItemsSource = mensLeaders;

    }

    private void mensRankings_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (mensRankings.SelectedItem != null)
        {
            Mens_Leaders SelectedPlayer = mensRankings.SelectedItem as Mens_Leaders;
            _SelectedMensPlayer = (sender as ListBox).SelectedItem;
            NavigationService.Navigate(new Uri("/Pages/PlayerProfile.xaml", UriKind.Relative));
            FrameworkElement root2 = Application.Current.RootVisual as FrameworkElement;
            root2.DataContext = _SelectedMensPlayer;
        }
    }

第二个列表加载的页面

private void LoadPlayerList()
    {
        Service1Client ServiceReference1Client = new Service1Client();

        ServiceReference1Client.GetTournamentListCompleted += new EventHandler<GetTournamentListCompletedEventArgs>(ServiceReference1Client_GetTournamentListCompleted);
        ServiceReference1Client.GetTournamentListAsync();

        FrameworkElement root2 = Application.Current.RootVisual as FrameworkElement;
        var currentPlayer = root2.DataContext as ATP_Tennis_App.TennisService.Mens_Leaders;
        _SelectedPlayer = currentPlayer;
        _selectedPlayerTournamentsWon = currentPlayer.Name;

    }
void ServiceReference1Client_GetTournamentListCompleted(object sender, GetTournamentListCompletedEventArgs e)
    {
        if (e.Error != null) { return; }

        ObservableCollection<Tournaments> tournamentList = e.Result;

        viewSource = new CollectionViewSource();
        viewSource.Filter += TournamentWin_Filter;
        viewSource.Source = tournamentList;
        this.listBox1.ItemsSource = viewSource.View;
    }

    void TournamentWin_Filter(object sender, FilterEventArgs e)
    {
        if (e.Item != null)
            e.Accepted = ((Tournaments)e.Item).Prev_Male_Winner.Contains(_selectedPlayerTournamentsWon);
    }

    private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (listBox1.SelectedItem != null)
        {

            Tournaments selectedTournament1 = listBox1.SelectedItem as Tournaments;

            _SelectedItemTournament = (sender as ListBox).SelectedItem;
            NavigationService.Navigate(new Uri("/Pages/TournamentDetailsPanorama.xaml", UriKind.Relative));
            FrameworkElement root3 = Application.Current.RootVisual as FrameworkElement;
            root3.DataContext = _SelectedItemTournament;

        }
        else
        {
            return;
        }
    }
4

2 回答 2

1

在列表框上,将 IsSynchroziedWithCurrentItem 设置为 False。这解决了这个问题。

于 2012-07-21T10:08:12.270 回答
0

我知道这是一个肮脏的解决方案,但您可以设置 listBox1.SelectedIndex = -1

于 2012-06-01T10:28:39.560 回答