What's the best way to clear a container

Nov 16, 2011 at 2:22 PM

I have a view that has 3 containers and it has one vm.

I populate one of the containers by binding to the container Url and SiteArea properties from the master vm, this then loads a child view and vm (this all works ok).

I then want to remove the child view from the container (and ideally no have to add anything else to the container). What is the best approach for doing this and correctly disposing of the child view/view model.

Would appreciate some help with this.

Nov 17, 2011 at 11:43 AM

I think you have two options:

1. Set the content of the container to be null - as all of the built in container are derived from ContentControl type.

2. or, Navigate to a blank-content page (you can use the built-in url: "about:blank")

Also, if the container supports navigation history functionality, then purge that by calling "PurgeJournal()" - see the ISupportJournalPurging type.

Hope this helps,

Nov 17, 2011 at 12:30 PM

Thanks for the help Rishi.

Right now I am navigating to an empty view which works but I didn't think it was the best solution.

I like the PurgeJournal() idea, can you tell me how I would purge from within xaml please (I can hook it up to a reverse command)

Nov 17, 2011 at 12:37 PM

@ultramods use the PurgeNavigationJournalAction behaviour action.. Note, not all containers support the Purge functionality, only the ones that store the navigation history do.


Nov 17, 2011 at 12:39 PM

@grogru FYI, the other built in address is "about:error" I believe - it implements ISupportNavigationFailure to display any navigation related errors.

Nov 17, 2011 at 12:44 PM

Ok, thanks again.