Silverlight MVVM MEF ViewInjection
Posted
by silverfighter
on Stack Overflow
See other posts from Stack Overflow
or by silverfighter
Published on 2010-03-04T17:34:02Z
Indexed on
2010/03/08
22:21 UTC
Read the original article
Hit count: 283
Hi all, since my title is buzzword compliant I hope I will get lots of answers to my question or any pointers to the right direction.
OK what I usually do is have a ViewModel which contains a list of ViewModels itself.
public class MasterViewModel
{
public ObservableCollection<DetailViewModel> DetailViewModels { get; set; }
public DetailViewModel Detail { get; set; }
}
<ItemsControl ItemsSource="{Binding DetailViewModels}">
<ItemsControl>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:DetailsView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
With this in mind I will now come to my questions. I read a lot of good things about MEF and also saw the dashboard sample of Glenn Block but this was not helping me enough.
What I want to do is sidbar (like the windows sidebar). Sidebar = StackPanel ListItems = Gadget
ButI want it MVVM style
OK I have something like a contract
IGadget
I implemented an custom Export.
[ExportGadget(GadgetType = GadgetTypes.News)]
I have my NewsGadgetView.xaml (which implements IGadget) and imports the NewsGadgetViewModel and also makes itself available as ExportGadget.
so far so good. With this I can create a set of gadgets.
Then I have my SidbarView.xaml which imports a sidebarViewModel.
and now I get lost...
I thought of something like a GadgetFactory which uses PartCreator to create my Gadgets. but this would sit in my SidebarView.xaml But I want to have control over my Gadgets to add and remove them from my sidebar. So I thought about something like an ObserveableCollection...
Which I bind to
The GadgetHost is basicaly Grid which will dynamicaly load the Gadget....
So how would I create my sidebar containing different gadgets without knowing which Gadgets are available and have a ViewModel for the sidebar as well as for each gadget?...
Thanks for any help....
© Stack Overflow or respective owner