How do I remove a Page from a Frame? - Community Credit Forums
in

    Community Credit Forums

How do I remove a Page from a Frame?

Last post Thu, Mar 20 2008 6:54 PM by jeremychaney. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • Wed, Mar 19 2008 5:06 PM

    How do I remove a Page from a Frame?

    In my app I have multiple tabs like Firefox and IE with close buttons for each tab. I accomplish this by hosting a Frame control and making each tab a Page. When the user closes a tab, I would like to remove it from the Frame where it is hosted, but I can't figure out how to do that. I thought that calling GoBack() to go to the previously selected tab and then RemoveBackEntry() would accomplish this, but it doesn't work. If I call GoForward(), then the old Page that should have been removed shows back up. How do I remove it?

    Thanks,
    --Jeremy
     

    Filed under:
  • Thu, Mar 20 2008 8:58 AM In reply to

    Re: How do I remove a Page from a Frame?

    Jeremy,

     Need to clear up a few things.

    1.  Are you actually using the TabControl and inserting TabPages?

    2.  Can you post the code and/or XAML that you are using to "add" a page to your application.

    3.  Do you want the end user to be able to navigate back and forth between pages as well as close a page?

     

    Cheers,

    Karl

    Code Project MVP, Karl's Blog : Get Mole v4 Here also!

    Just a grain of sand on the worlds beaches.
  • Thu, Mar 20 2008 9:03 AM In reply to

    • MarlonGrech
    • Top 75 Contributor
    • Joined on Sat, Dec 22 2007
    • Victoria, Malta
    • Posts 8

    Re: How do I remove a Page from a Frame?

    Hi there,

     Can you please post the XAML or code you are using?

    Regards 

  • Thu, Mar 20 2008 11:54 AM In reply to

    Re: How do I remove a Page from a Frame?

    Here is my code:

     

    private voice AddNewTab()

     DocumentControl documentControl = new DocumentControl();
     DocumentParent.Content = DocumentControl;

     

    ...(other code that create a Button, and sets this document control as its Tag property so that when the button is clicked I can call DocumentParent.Navigate(tabButton.Tag); )

     }

     

    And yes, I do want to user to be able to navigate back and forth, as well as close the page. 

  • Thu, Mar 20 2008 12:30 PM In reply to

    Re: How do I remove a Page from a Frame?

    I assume that the Close Button is on the child document, correct?

    Since the parent is the object that must remove the child, have the child close button raise a routed event or routed command and have the parent control service the event and remove that clild from its collection of children.

    Cheers,

    Karl

    Code Project MVP, Karl's Blog : Get Mole v4 Here also!

    Just a grain of sand on the worlds beaches.
  • Thu, Mar 20 2008 1:01 PM In reply to

    Re: How do I remove a Page from a Frame?

     I can't. The parent is a Frame object- it doesn't have Children in the traditional sense. You add children to it by assigning the Content property to the child control. The Frame then internally manages the children and doesn't give you access to them.

  • Thu, Mar 20 2008 2:35 PM In reply to

    Re: How do I remove a Page from a Frame?

    I'm sorry I don't understand what you are trying to do.

     Can you post your XAML and code here.

    Cheers,

    Karl

    Code Project MVP, Karl's Blog : Get Mole v4 Here also!

    Just a grain of sand on the worlds beaches.
  • Thu, Mar 20 2008 4:11 PM In reply to

    Re: How do I remove a Page from a Frame?

     The code is rather involved and contains a bunch of other stuff that I would rather not post. I hope you understand. Let me try to explain more clearly:

     

    In my application window I have a Grid with three rows- a menu bar, a tab bar (my own implemenation- horizontal stack panel with  radio buttons), and a Frame control which hosts my document control wich derives from Page. From the menus, the user has the ability to create a new tab. Each time a new tab is created, I add a button to the tab bar, and create a new document control and set the Frame controls Content property to the new document (Page control). So for every new document I create, I add a button to the tab bar, and the Frame gets another control added to its NavigationService, but only the one assigned to its Content property is visible (and as you probably know, you switch between the pages by calling the many different Navigate functions). So that is my set up. Now on to the problem. You user also has the ability to close each tab. When the user closes a tab, I remove the button from the tab bar, and I want to remove the document (Page object) from the Frame control. The problem is that Frame controls don't expose a Children property, and (from what I can tell) don't provide any way to remove a Page once it has been added (via assign the Page to the Frames Content property). There is a method called RemoveBackEntry() which I hoped would remove the last entry in the cache once I navigated away from a page, but it does not seem to do that. I call RemoveBackEntry(), then call GoBack() and the Frame displays the control that should have been removed.

     

    --Jeremy

     

  • Thu, Mar 20 2008 6:24 PM In reply to

    Re: How do I remove a Page from a Frame?

    Is there a reason you not using the TabControl?

     I have a post that shows you the basics of MDI with a TabControl.  http://karlshifflett.wordpress.com/2008/02/24/wpf-sample-series-wpf-mvc-tabcontrol-mdi-and-commandbindings/

    Can each "Content" page navigate to other other content pages.  Not speaking about other Content in your frames, I'm speaking about navigating to other content within that same frame page? 

     

     

    Cheers,

    Karl

    Code Project MVP, Karl's Blog : Get Mole v4 Here also!

    Just a grain of sand on the worlds beaches.
  • Thu, Mar 20 2008 6:54 PM In reply to

    Re: How do I remove a Page from a Frame?

    Actually it looks like a TabControl is what I'm looking for after all. Thanks! 

Page 1 of 1 (10 items)
Powered by Community Server (Commercial Edition), by Telligent Systems