MEF & Silverlight: how to go to a page in another XAP?

I really lost how to do this.

I understand MEF and can load services and classes from another XAP using the ubiquitous DeploymentCatalogService, which can be found in many blog posts. I do not understand how to download and go to PAGE from another XAP.

What I would like to do is that my main application will be able to call the NavigationService and provide it with the name of the page that should exist. For instance:

 NavigationService.Navigate(new Uri("/Test", UriKind.Relative));

To one of the other XAP files to provide this page for the application. However, I do not know how to do this. Everyone seems to be creating complex infrastructure to deal with this situation, and it is very annoying and overly complicated.

Is there an easy way to do this?

+3
source share
2 answers

Some of the examples I've seen are more complicated than they should be, but this is not an easy task. It took me 2 days to break down the examples that I could find before I really understood what was going on.

To do this, you need to create at least two classes. A class that implements INavigationContentLoader will do all the work. A class that implements IAsyncResult. This object will be passed to INavigationContentLoader, so use it to keep track of what you are doing.

Your INavgiationContentLoader should do the following.

Beginload

  • Check if Uri belongs to the current XAP or XAP that has already been loaded.
    • If not, use DeploymentCatalog to download XAP. Store DeploymentCatalog in AggregateCatalog.
  • Uri, ExportFactory. IAsyncResult, .
  • , .

CanLoad

, , XAP, true .

CancelLoad

IAsyncResult, , .

EndLoad

  • , IAsyncResult, LoadResult .


, INavgiationContentLoader, ExportAttribute, ExportFactory .

My InavigationContentLoader

http://pastebin.com/cT1mJ4Ve

IAsyncResult

http://pastebin.com/xHWHT4pr

ExportAttribute . all, XAP.

http://pastebin.com/nTJ27mWz

IExportPageMetaData. , MEF.

http://pastebin.com/8fdwx2Kn

:

: ,

<navigation:Frame x:Name="ContentFrame"
                  Source="/Home"`
                  Grid.Column="1"> 
    <navigation:Frame.ContentLoader>
        <navUtil:DynamicContentLoader />
    </navigation:Frame.ContentLoader>
</navigation:Frame>

HyperlinkButton XAP.

<HyperlinkButton Content="Page from another XAP"
                 NavigateUri="/NavigateUriFromExportPageAttribute"
                 navUtil:DynamicContentLoader.Xap="UriToOtherXap" />

HyperlinkButton XAP.

<HyperlinkButton Content="Page from this XAP"
                 NavigateUri="/NavigateUriFromExportPageAttribute" />

UriMapper, Path of the page.xaml. MEF ExportPageAttribute Uri .

+3

All Articles