Files
wpf-notifyicon/Source/Sample Project/Tutorials/09 - MVVM/MvvmSampleViewModel.cs
Philipp Sumi e0f4d731ca ADD MVVM Sample.
NTFY-24

git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@198 9f600761-6f11-4665-b6dc-0185e9171623
2013-11-22 23:37:09 +00:00

38 lines
1.1 KiB
C#

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
namespace Samples.Tutorials.MvvmSample
{
public class MvvmSampleViewModel : INotifyPropertyChanged
{
private DispatcherTimer timer;
public string Timestamp
{
get { return DateTime.Now.ToLongTimeString(); }
}
public MvvmSampleViewModel()
{
timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, OnTimerTick, Application.Current.Dispatcher);
}
private void OnTimerTick(object sender, EventArgs e)
{
//fire a property change event for the timestamp
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("Timestamp")));
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}