0

I am developing an application in WPF using MVVM, but I am stuck. I have a windows which contains one buttons, so, I bind this to respective ICommand in XAML as below:

<Button Content="Login"
                Command="{Binding Path=LoginCommand,Mode=OneWay}" />

View Model is :

private ICommand _loginCommand;
    public ICommand LoginCommand
    {
        get
        {
            if (_loginCommand == null)
            {
                _loginCommand = new RelayCommand(
                    param => this.Login()
                        );
            }
            return _loginCommand;
        }
    }

the Login Method:

private void Login()
    {
        //Open Main Window Here
        //MainWindow obj=new MainWindow ();
        //obj.Show();

        //How to Close Login Window ?
    }

I want How to Open New window when Login Button Click and close the login Window itself .How to accomplish this?

Angel
  • 309
  • 3
  • 13
  • What you are doing is not MVVM. ViewModel can't have any knowledge about the view. But your ViewModel does, as it calls MainWindow – Tseng Feb 24 '14 at 11:41
  • @Tseng ,I know its a violation of MVVM .But I dont know how to open a View Here – Angel Feb 24 '14 at 11:44
  • @Angel have a look at [This answer](http://stackoverflow.com/a/16994523/1834662). Download the attached example and try it out. It should answer your questions. – Viv Feb 24 '14 at 12:38

0 Answers0