views:

9

answers:

1

I'm having trouble figuring out how to cache pages already visited in my silverlight application. I have an array of URIs declared like so:

 let pages : UriUserControl array = [|
        new Module1.MyIdeas() :> UriUserControl ;
        new Module1.Page2() :> UriUserControl ;
        new Module1.Page3() :> UriUserControl ;
        new Module1.Page4() :> UriUserControl ; 
        new Module1.Page5() :> UriUserControl ; |]

I have a navigation frame on the page and I handle the navigation like so (nav is the Frame object on the template page):

member this.navigate (ea: SelectedMenuItemArgs) = 
        let i  = ea.Index
        if i <= pages.Length then         
            let page = (pages.[i-1] :> INamedUriProvider)  
            nav.Navigate(page.Uri) |> ignore
            pageTitle.Text <- page.ProviderName

I'm looking for a way to avoid re-creating the page on subsequent navigations to the URI. I thought of keeping a map of URI -> nav.Content but nav.Content and setting the navs content based on this cache. Any ideas?

+1  A: 

My original post was incomplete, I forgot to include that UriUserControl inherited UserControl and the root element for each xaml was UserControl ie;

type UriUserControl(uriStr, name) as this = 
    inherit UserControl()
    member this.uri = new System.Uri(uriStr, UriKind.Relative)
    member this.providerName = name
    interface INamedUriProvider with 
        member this.Uri with get() = this.uri
        member this.ProviderName with get() = this.providerName

I changed this implementation to use System.Windows.Controls.Page instead of UserControl (also changing the UserControl's to Page's in the xaml). This enables the Frame to use the caching functionality of NavigationService, which not only gets you caching, but also enables the browser back and forward buttons within the application.

PhilBrown