Language: C#
MEF and Design Time in Silverlight with no App.cs
public class ViewModelLocator {
public ViewModelLocator() {
//if (!ViewModelBase.IsInDesignModeStatic)
CompositionInitializer.SatisfyImports(this);
}
//If I do not use AllowDefault = true, the Design Time blows up saying it cannot
// match the export to the import
[Import(AllowDefault = true)]
public OrbitScreenViewModel SomeViewModelInstance { get; set; }
[Import(AllowDefault = true)]
public LeaseViewModel LeaseViewModel { get; set; }
}
[Export]
public class OrbitScreenViewModel : ViewModelBase {
public OrbitScreenViewModel() {
if (IsInDesignMode) {
// Code runs in Blend --> create design time data.
}
else { //Do runtime things
}
}
}
//There is no App.cs or App.xaml because this is a dynamically loaded xap package for App Partioning
<Navigation:DynamicPage xmlns:vm="clr-namespace:DataForms.Locator" x:Class="DataForms.Screen"
d:DesignWidth="800" d:DesignHeight="700"
NavigationCacheMode="Enabled"
Title="Data">
<Navigation:DynamicPage.Resources>
<vm:ViewModelLocator x:Key="VMLocator"/>
</Navigation:DynamicPage.Resources>
<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource VMLocator}, Path=SomeViewModelInstance }">
...
<local:SomeUserControl DataContext="{Binding Source={StaticResource VMLocator}, Path=LeaseViewModel }"/ > </Grid>
Description:
I am trying to get MEF to load in my ViewModels and use the Service Locator pattern to be able to design it. It works fine in runtime, but at design time it will not work. I can get it to work if I do AllowDefault = true on the import, because it cannot find the exports to match it. Is there any reason MEF cannot find the Exports in a Silverlight Application that has no App.cs?
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

