This is my login xaml file (View):
<page x:class="WolfswoodInCinch.Login" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CinchV2="clr-namespace:Cinch;assembly=Cinch.WPF"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
xmlns:views="clr-namespace:WolfswoodInCinch.Views"
Title="Wolfswood Coach Booking System" Height="350" Width="525"
xmlns:meffed="http:\\www.codeplex.com\MEFedMVVM"
meffed:ViewModelLocator.ViewModel="LoginViewModel">
<grid height="193" width="236">
<label content="Wolfswood Coach Booking Application" height="28" horizontalalignment="Left" margin="10,10,0,0" name="label1" verticalalignment="Top" />
<label content="Login" height="28" horizontalalignment="Left" margin="10,31,0,0" name="label2" verticalalignment="Top" />
<textblock text="{Binding Path=Error, Mode=TwoWay}" foreground="Red"></textblock>
<label content="Username: " height="28" horizontalalignment="Left" margin="10,78,0,0" name="label3" verticalalignment="Top" />
<label content="Password: " height="28" horizontalalignment="Left" margin="10,112,0,0" name="label4" verticalalignment="Top" />
<textbox height="23" horizontalalignment="Left" margin="82,83,0,0" name="textBox1" verticalalignment="Top" width="120" text="{Binding UserName.DataValue, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}">
<i:interaction.behaviors xmlns:i="#unknown">
<cinchv2:textboxfocusbehavior isusingdatawrappers="True" xmlns:cinchv2="#unknown" />
<cinchv2:textboxfocusbehavior xmlns:cinchv2="#unknown" />
</i:interaction.behaviors>
</textbox>
<textbox height="23" horizontalalignment="Left" margin="82,117,0,0" name="passwordBox1" verticalalignment="Top" width="120" text="{Binding Password.DataValue, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}">
<i:interaction.behaviors xmlns:i="#unknown">
<cinchv2:textboxfocusbehavior isusingdatawrappers="True" xmlns:cinchv2="#unknown" />
<cinchv2:textboxfocusbehavior xmlns:cinchv2="#unknown" />
</i:interaction.behaviors>
</textbox>
<button content="Login" isdefault="True" height="23" horizontalalignment="Left" margin="149,158,0,0" name="button1" command="{Binding LoginViewFiredCommand}" verticalalignment="Top" width="75" click="button1_Click">
</button>
<textblock text="{Binding Path=loginResult}" horizontalalignment="Left" margin="12,146,0,12" name="textBlock1" width="131" />
</grid>
</page>
And this is my MV class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.ComponentModel;
using WolfswoodInCinch.Views;
using WolfswoodInCinch.Classes;
using WolfswoodInCinch.Commands;
using MEFedMVVM.ViewModelLocator;
using Cinch;
using System.ComponentModel.Composition;
using System.Windows.Navigation;
namespace WolfswoodInCinch.ViewModels
{
[ExportViewModel("LoginViewModel")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class LoginViewModel : ViewModelBase
{
private DataWrapper<string> userName;
private DataWrapper<string> password;
private IEnumerable<datawrapperbase> cachedListOfDataWrappers;
public LoginWindow Parent { get; set; }
[ImportingConstructor]
public LoginViewModel()
{
UserName = new DataWrapper<string>(this, userNameChangeArgs);
UserName.IsEditable = true;
Password = new DataWrapper<string>(this, passwordChangeArgs);
Password.IsEditable = true;
cachedListOfDataWrappers = DataWrapperHelper.GetWrapperProperties<loginviewmodel>(this);
LoginViewFiredCommand = new SimpleCommand<object,>(ExecuteLoginCommand);
}
static PropertyChangedEventArgs userNameChangeArgs = ObservableHelper.CreateArgs<loginviewmodel>(y => y.UserName);
public DataWrapper<string> UserName
{
get { return userName; }
private set
{
userName = value;
NotifyPropertyChanged(userNameChangeArgs);
}
}
static PropertyChangedEventArgs passwordChangeArgs = ObservableHelper.CreateArgs<loginviewmodel>(x => x.Password);
public DataWrapper<string> Password
{
get { return password; }
private set
{
password = value;
NotifyPropertyChanged(passwordChangeArgs);
}
}
public SimpleCommand<object,> LoginViewFiredCommand { get; private set; }
private void ExecuteLoginCommand(EventToCommandArgs args)
{
string username = UserName.DataValue;
string password = Password.DataValue;
loginResult = "Successful login";
}
string result;
public string loginResult
{
get { return result; }
set
{
result = value;
NotifyPropertyChanged(_loginResultChangeArgs);
}
}
static PropertyChangedEventArgs _loginResultChangeArgs = ObservableHelper.CreateArgs<loginviewmodel>(x => x.loginResult);
}
}
</loginviewmodel></string></loginviewmodel></string></loginviewmodel></loginviewmodel></string></string></datawrapperbase></string></string>
What I want to be able to do is in the ViewModel's ExecuteLoginCommand method, close the window if the user has successfully logged in, and then view the main application. I appreciate at present there isn't any data validation, this will come once the fundamentals have been implemented.