Created
July 31, 2014 19:39
-
-
Save julesx/0cd80e7dfb8c38daaf37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Input; | |
using WpfApplication30.Annotations; | |
namespace WpfApplication30 | |
{ | |
public partial class MainWindow : INotifyPropertyChanged | |
{ | |
private bool _doingWork; | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
DataContext = this; | |
} | |
public bool DoingWork | |
{ | |
get { return _doingWork; } | |
set | |
{ | |
_doingWork = value; | |
OnPropertyChanged("DoingWork"); | |
} | |
} | |
public void ButtonClicked(object o) | |
{ | |
DoingWork = true; | |
Task.Factory.StartNew(delegate | |
{ | |
//Look at me doing some work, going to take about 15 seconds | |
Thread.Sleep(15000); | |
}).ContinueWith(t => | |
{ | |
DoingWork = false; | |
}); | |
} | |
private RelayCommand _buttonClicked; | |
public ICommand CmdButtonClicked { get { return _buttonClicked ?? (_buttonClicked = new RelayCommand(ButtonClicked)); } } | |
public event PropertyChangedEventHandler PropertyChanged; | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChangedEventHandler handler = PropertyChanged; | |
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment