I'm not sure what you're going for, but it sounds like you want to track how "fresh" or "stale" the live value coming from the feed is. If so, INotifyPropertyChanged (the power behind Dependency Properties) is probably not going to make you happy, since it's going to depend entirely on the implementation of that interface as to whether or not you'll be told when a SAMPLE IS TAKEN vs. when the SAMPLE HAS CHANGED (they're not the same concept).
Depending on how much control you have over this, I'd recommend implementing the "Stale" tracking inside your ViewModel (you are using MVVM, right?)
Something like:
Model.cs:
using System;
using System.Windows.Threading;
namespace WpfApplication1
{
public class Model
{
private readonly double[] _data = new[] { 2.3, 2.4, 2.5, 2.4, 2.1, 2.1, 2.1, 2.1, 2.0, 2.1, 2.0, 2.1, 2.2, 2.2, 2.2, 2.2, 2.2, 2.4 };
private readonly DispatcherTimer _timer = new DispatcherTimer();
private int _nextSample;
public Model()
{
_timer.Interval = new TimeSpan(0, 0, 0, 1);
_timer.Tick += _timer_Tick;
_timer.Start();
}
public event EventHandler<SampleTakenEventArgs> SampleTaken;
private void _timer_Tick(object sender, EventArgs e)
{
if (SampleTaken != null)
{
SampleTaken(this, new SampleTakenEventArgs { SampleValue = _data[_nextSample] });
}
_nextSample = (++_nextSample%_data.Length);
}
}
}
View.xaml:
<Window x:Class="WpfApplication1.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBlock Text="{Binding Sample}"/>
<TextBlock Text="{Binding StaleCount}"/>
</StackPanel>
</Window>
View.xaml.cs:
using System.Windows;
namespace WpfApplication1
{
public partial class View : Window
{
public View()
{
InitializeComponent();
DataContext = new ViewModel();
}
}
}
ViewModel.cs:
using System.ComponentModel;
namespace WpfApplication1
{
public class ViewModel : INotifyPropertyChanged
{
private readonly Model _model;
private double _sample;
private int _staleCount;
public ViewModel()
{
_model = new Model();
_model.SampleTaken += _model_SampleTaken;
}
public double Sample
{
get { return _sample; }
set
{
_sample = value;
OnPropertyChanged("Sample");
}
}
public int StaleCount
{
get { return _staleCount; }
set
{
_staleCount = value;
OnPropertyChanged("StaleCount");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
private void _model_SampleTaken(object sender, SampleTakenEventArgs e)
{
if (e.SampleValue == Sample)
{
StaleCount++;
}
else
{
StaleCount = 0;
}
Sample = e.SampleValue;
}
protected void OnPropertyChanged(string propertyName)
{
var propertyChanged = PropertyChanged;
if (propertyChanged != null)
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}