I need to create an instance of ViewModel with a specific parameter passed to the ViewModel when it is created. At the same time, this ViewModel instance must be registered with SimpleIOC
I thought this was a method for him:
SimpleIoc.Register<TClass> Method (Func<TClass>, String, Boolean)
with true for the last parameter for instant creation. therefore, if I understood correctly, this method wants a reference to the method that will create my ViewModel instance.
This is called ClassFactory, as it seems.
I tried to do it myself, but all I get is
cannot convert from <Class> to System.Func<Class>
so it seems that im always passes an instance of the class, not the method that should create it.
can someone give a short example of how i can make this work
public class ClassFactory { public ChatWindow CreateChatWindow(RosterItemX ri) { return new ChatWindow(ri); } } public class ViewModelLocator { . . . . public static void CreateWindow(RosterItemX riv) { ClassFactory cf = new ClassFactory; SimpleIoc.Default.Register<ChatWindow>(cf.CreateChatWindow(ri), "key", true ) var _messageWindow = new MessageWindow(); _messageWindow.Show(); } } class ChatMessage { RosterItemX ri = new RosterItemX(); ViewModelLocator.CreateWindow(ri); }
c # ioc-container mvvm-light
Themis Feb 23 '16 at 19:44 2016-02-23 19:44
source share