I have a huge problem with MEF when I try to dynamically load XAP files. When I load the directory / xap file with the dc.DownloadAsync () method call; My Internet Explorer will work and show me that the "IE has stopped working" dialog. (see image belove).
I followed a few steps on the step instructions and I just can't figure out what I'm doing wrong or what I missed.
OverView of my solution explorer (Se image at the end of the post for a more detailed view):
AppStation Solution
- AppStation.Common
- AppStation.GUI
- Test2
Interface:
public interface IApp
{
string Name { get; }
string Description { get; }
UserControl GetUserInterface();
}
Implementation:
[Export(typeof(IApp))]
public class HelloMefApp : IApp
{
public string Name
{
get { return "Hello MEF"; }
}
public string Description
{
get { return "Adds a label with the text 'Hello MEF'"; }
}
public UserControl GetUserInterface()
{
UserControl uc = new UserControl();
TextBlock textBlock = new TextBlock();
textBlock.Text = "Hello MEF";
uc.Content = textBlock;
return uc;
}
}
App.xaml.cs, Application_Startup, XAP dynamic download:
private void Application_Startup(object sender, StartupEventArgs e)
{
AggregateCatalog catalog = new AggregateCatalog();
DeploymentCatalog dc = new DeploymentCatalog(new Uri("Test2.xap", UriKind.Relative));
catalog.Catalogs.Add(dc);
dc.DownloadAsync();
CompositionHost.Initialize(catalog);
this.RootVisual = new MainPage();
}
MainPage:
public partial class MainPage : UserControl, IPartImportsSatisfiedNotification
{
[ImportMany(AllowRecomposition = true)]
public IApp[] Apps { get; set; }
public MainPage()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
}
public void OnImportsSatisfied()
{
if (Apps != null)
{
foreach (IApp item in Apps)
{
LayoutRoot.Children.Add(item.GetUserInterface());
}
}
}
}
alt text http://www.colincochrane.com/image.axd?picture=WindowsLiveWriter/InternetExplorer8Beta1FirstImpressions_117C3/ie8-2_thumb.jpg
alt text http://www.freeimagehosting.net/uploads/cf93454c1a.jpg
LJ:
Test2 - Silverlight, howedver, App.xaml MainPage.xaml, , . , .XAP.
, , .
, :
dc.DownloadCompleted += (s, args) =>
{
int x = 10;
};
dc.DownloadProgressChanged += (s, args) => {
int x = 10;
};
, , , ( ) .
: Expetion:
Exception has been Thrown by the target of an invocation.
at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)
at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
Caused by: Exception has been thrown by the target of an invocation.
at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)
at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)