简体   繁体   中英

What is the best way to discard of a WPF page in order to display a new version of that page with different data?

In my program, navigation is structured along a path going Project->Board->Issue, then you are able to navigate back up to choose a different board. It displays the issues in a list which can be picked from. The trouble is that if you navigate to a different board, then choose a different issue from the ones displayed there, it still displays the first issue you selected.

I think the best solution is to dispose of the issue detail page when I navigate back, but I am unsure of how to do this.

Navigation from Board to Issues

private void BtnSelect_Click(object sender, RoutedEventArgs e)
{
    var loginWindow = Window.GetWindow(this) as MainWindow;
    if (selectedBoard != null)
    {
        PageIssueSelect p = null;
        p = new PageIssueSelect(project, selectedBoard);
        loginWindow.Navigate(p);
    }
}

Navigation from Issue list back to Board:

private void BtnBack_Click(object sender, RoutedEventArgs e)
{
    items.Clear();
    lbxIssues.ItemsSource = null;
    project = null;
    var mainWindow = Window.GetWindow(this) as MainWindow;
    mainWindow.pageHolder.GoBack();
}

Navigation from Issue list to one issue:

private void LbxIssues_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    ListBox box = (ListBox)sender;
    var loginWindow = Window.GetWindow(this) as MainWindow;
    Issue issue = project.Issues[box.SelectedIndex];
    pageIssueDetail p = null;
    p = new pageIssueDetail(issue, project.name);
    loginWindow.Navigate(p);
}

Navigation from one issue back to the issue list

{
    issue = null;
    var loginWindow = Window.GetWindow(this) as MainWindow;
    loginWindow.pageHolder.GoBack();
}

As far as I can tell, there should be no reason for the same issue to always be displayed, as each time it navigates forward it is creating a new page with a new issue selected.

Some of the unnecessary code lines in these are from me trying to create some kind of solution to the matter.

The issue laid in the data being fetched, not the pages. I was using

item = wholeList[index];

When I should have been using

item = filteredList[index];

Just answering in case this helps anyone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM