I have a function that is designed to create an instance of a window and return me a RelayCommand
(basically, it's just an MVVMLite helper method:
public static RelayCommand NavigateTo(Type navigateTo)
{
var relayCmd = new RelayCommand (() => Navigate(navigateTo));
return relayCmd;
}
private static void Navigate(Type navigateTo)
{
var newWin = Activator.CreateInstance(navigateTo);
((Window)newWin).Show();
}
I then call this in a separate class like this:
this.MyCommand = Navigation.NavigateTo(View.MyView);
MyView is a valid Window, however, I get the following compile error:
The best overloaded method match for 'MyProject.Navigation.NavigateTo(System.Type)' has some invalid arguments
I can make it work, by doing this:
this.MyCommand = Navigation.NavigateTo(typeof(View.MyView));
My question is: why? I'm passing a type and expecting a type. Also, is there a way that I can get my NavigateTo
function to simply accept the class name of the Window?