I'm not clear on what is connecting to whom and how, so let me tell you how I'd do it.
ODP constructs an instance of clsPatients, which contains a "collection" filled with "data".
public class clsPatients, INotifyPropertyChanged
{
public IBindingList Data {get;private set;}
private DispatcherTimer _timer;
public ClsPatients()
{
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(someInterval);
_timer.Tick += DispatcherTimerTick;
_timer.Start();
}
/* etc etc */
}
clsPatients also has a DispatcherTimer which, on a regular interval updates the Data property and fires PropertyChanged
public void DispatcherTimerTick(object sender, EventArgs e)
{
Data = new BindingList(Repository.GetMyDataLol());
// standard event firing method here, move along:
OnPropertyChanged("Data");
}
In the UI, I'd bind against this collection thusly (this may be bug free, or maybe its not):
<ItemsControl
ItemsSource="{Binding Data Source={StaticResource WaitingPatientDS}}">
<ItemsControl.Resources>
<DataTemplate>
<!-- yadda -->
How this works to update the UI when Data is updated:
- clsPatient is provided to the ItemsControl by the ObjectDataProvider
- ItemsControl uses the WPF binding infrastructure to bind against the Data property of the instance provided by the ODP.
- The DispatcherTimer (operating on the UI thread) of the clsPatient updates Data and fires PropertyChanged, which notifies all bindings subscribing to this event that the property has ironically enough changed
- The binding takes over and refreshes the ItemsControl
To show an animation that indicates loading is in progress, add another property to clsPatient called Loading:
public Visibility Loading{get;private set}
and update the timer tick event:
public void DispatcherTimerTick(object sender, EventArgs e)
{
Loading = Visibility.Visible;
OnPropertyChanged("Loading");
Data = new BindingList(Repository.GetMyDataLol());
OnPropertyChanged("Data");
Loading = Visibility.Hidden;
OnPropertyChanged("Loading");
}
then, in the ui, bind your indicator's Visibility property to Loading:
<Grid DataContext="{Binding Data Source={StaticResource WaitingPatientDS}}">
<ItemsControl
ItemsSource="{Binding Data}">
<ItemsControl.Resources>
<DataTemplate>
<!-- yadda -->
</ItemsControl>
<Image Source="hurf.jpg" Visibility="{Binding Loading}"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
the Image (or whatever other control you want to use) appears when Loading is set to Visible and goes away when its set to Hidden. So you can show the image when you're loading data.
If the UI isn't updating, the process is probably blocking the UI as its executing in the UI thread.
To fix this, run a System.Threading.Timer instead of a DispatcherTimer. STT runs on a background thread other than the UI. In the timer's callback method, use the dispatcher to update the ui (the Invoke methods may be buggy; check the docs on Dispatcher.Invoke):
public void UpdateData(Object stateInfo)
{
var disp = Dispatcher.CurrentDispatcher();
Loading = Visibility.Visible;
disp.Invoke(() => { OnPropertyChanged("Loading");});
// optional sleep here
Data = new BindingList(Repository.GetMyDataLol());
disp.Invoke(() => { OnPropertyChanged("Data");});
Loading = Visibility.Hidden;
disp.Invoke(() => { OnPropertyChanged("Loading");});
}