|
|
@@ -1,64 +1,63 @@
|
|
|
-using GalaSoft.MvvmLight;
|
|
|
+using System;
|
|
|
+using System.Windows.Threading;
|
|
|
using Editor.Model;
|
|
|
+using GalaSoft.MvvmLight;
|
|
|
+using GalaSoft.MvvmLight.Command;
|
|
|
+using GalaSoft.MvvmLight.Threading;
|
|
|
|
|
|
namespace Editor.ViewModel
|
|
|
{
|
|
|
- /// <summary>
|
|
|
- /// This class contains properties that the main View can data bind to.
|
|
|
- /// <para>
|
|
|
- /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
|
|
|
- /// </para>
|
|
|
- /// <para>
|
|
|
- /// See http://www.galasoft.ch/mvvm/getstarted
|
|
|
- /// </para>
|
|
|
- /// </summary>
|
|
|
public class MainViewModel : ViewModelBase
|
|
|
{
|
|
|
private readonly IDataService dataService;
|
|
|
+ private string loginResult = "";
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// The <see cref="WelcomeTitle" /> property's name.
|
|
|
- /// </summary>
|
|
|
- public const string WelcomeTitlePropertyName = "WelcomeTitle";
|
|
|
-
|
|
|
- private string welcomeTitle = string.Empty;
|
|
|
+ public MainViewModel(IDataService dataService)
|
|
|
+ {
|
|
|
+ this.dataService = dataService;
|
|
|
+ LoginCmd = new RelayCommand(AsyncLogin);
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets the WelcomeTitle property.
|
|
|
- /// Changes to that property's value raise the PropertyChanged event.
|
|
|
- /// </summary>
|
|
|
- public string WelcomeTitle
|
|
|
+ public string LoginResult
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- return welcomeTitle;
|
|
|
+ return loginResult;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
- if (welcomeTitle == value)
|
|
|
+ if (loginResult == value)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- welcomeTitle = value;
|
|
|
- RaisePropertyChanged(WelcomeTitlePropertyName);
|
|
|
+ loginResult = value;
|
|
|
+ RaisePropertyChanged("LoginResult");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Initializes a new instance of the MainViewModel class.
|
|
|
- /// </summary>
|
|
|
- public MainViewModel(IDataService dataService)
|
|
|
+ public RelayCommand LoginCmd
|
|
|
{
|
|
|
- this.dataService = dataService;
|
|
|
- dataService.GetData((item, error) =>
|
|
|
+ get;
|
|
|
+ private set;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AsyncLogin()
|
|
|
+ {
|
|
|
+ Action showLoginResult = () =>
|
|
|
+ {
|
|
|
+ LoginResult = "Login OK!";
|
|
|
+ };
|
|
|
+ AsyncCallback callback = (obj) =>
|
|
|
+ {
|
|
|
+ DispatcherHelper.UIDispatcher.BeginInvoke(
|
|
|
+ DispatcherPriority.Normal, showLoginResult);
|
|
|
+ };
|
|
|
+
|
|
|
+ Action asynLogin = () =>
|
|
|
{
|
|
|
- if (error != null)
|
|
|
- {
|
|
|
- // Report error here
|
|
|
- return;
|
|
|
- }
|
|
|
- WelcomeTitle = item.Title;
|
|
|
- });
|
|
|
+
|
|
|
+ };
|
|
|
+ asynLogin.BeginInvoke(callback, null);
|
|
|
}
|
|
|
|
|
|
public override void Cleanup()
|