In the following code, you can call the CheckDataShowWindow() method anytime you want to show windows when the data is ready. If you want to add it to another cick handler, you can just do something else like this:
public void Another_Click(object sender, RoutedEventArgs e) { CheckDataShowWindow(); }
Main code :
public void FirstMenuItem_Click(object sender, RoutedEventArgs e) { CheckDataShowWindow(); } private void CheckDataShowWindow() { if (!DataRepository.IsAllDataLoaded) { Timer t = new Timer(); t.Interval = 0.2; t.AutoReset = false; t.Elapsed += (s,e) => CheckDataShowWindow(); t.Start(); } else { Dispatcher.BeginInvoke(new Action(() => { IndividualEntryWindow Window = new IndividualEntryWindow(); Window.Show(); })); } }
Update
If you can edit the data warehouse code, you must add an event to load the data.
public delegate void DoneLoadingHandler(object sender, EventArgs e); public class DataRepository { public event DoneLoadingHandler DoneLoading;
Now in your other class:
public void FirstMenuItem_Click(object sender, RoutedEventArgs e) { CheckDataShowWindow(); } private bool AllReadyWaiting = false; private void CheckDataShowWindow() { if (!DataRepository.IsAllDataLoaded) { if(!AllReadyWaiting) { DataRepository.DoneLoading += (s,e) => ShowWindow(); AllReadyWaiting = true; } } else { ShowWindow(); } } private void ShowWindow() { Dispatcher.BeginInvoke(new Action(() => { IndividualEntryWindow Window = new IndividualEntryWindow(); Window.Show(); })); }
source share