Ich benutze Calibrn Micro und MEF in WPF und ich habe dieses Problem.Parameter vom Ansichtsmodell zum Konstruktor eines anderen Ansichtsmodells senden
Ich schaffe Shell-View-Modell:
public interface IShellViewModel
{
void ShowLogOnView();
void ShowMessengerView(PokecAccount account);
}
[Export(typeof(IShellViewModel))]
public class ShellViewModel : Conductor<IScreen>, IShellViewModel
{
public ShellViewModel()
{
ShowLogOnView();
}
public void ShowLogOnView()
{
ActivateItem(IoC.Get<LogOnViewModel>());
}
public void ShowMessengerView(PokecAccount account)
{
//send to constructor of MessangerViewModel paramter typeof PokecAccount(own class)
ActivateItem(IoC.Get<MessengerViewModel>(account));
}
}
Aus Sicht-Modell
ich schaffen und zeigen in neue Ansicht-Modell[Export]
public class LogOnViewModel : Screen, IDataErrorInfo, ILogOnViewModel
{
[Import]
private IShellViewModel _shellViewModel;
[Import]
private IPokecConnection _pokecConn;
private PokecAccount _account;
public void LogOn(string nick, string password)
{
_account = _pokecConn.LogOn(nick, password);
if (_account != null)
{
//create new view-model and show it, problem is send parameter to construtor of MessengerViewModel
_shellViewModel.ShowMessengerView(_account);
}
}
}
Problem ist hier
//send to constructor of MessangerViewModel paramter typeof PokecAccount(own class)
ActivateItem(IoC.Get<MessengerViewModel>(account));
New Ansichtsmodell
[Export]
public class MessengerViewModel : Screen, IMessengerViewModel
{
private PokecAccount _account;
public MessengerViewModel(PokecAccount account)
{
_account = account;
}
}
Problem ist hier:
//send to constructor of MessangerViewModel paramter typeof PokecAccount(own class)
ActivateItem(IoC.Get<MessengerViewModel>(account));
Parameter IoC.Get() nur Zeichenfolge sein kann.
Wie dieses Problem lösen?
Vielen Dank für Fortschritte, ich versuche ihre ... –