last day (15 days later) » 

11:20 PM
2
A: Based on a combo box value, change refresh timers

Clay Ver ValenTry this (or something very similar): private void RefreshTick_Change(object sender, SelectionChangedEventArgs e) { timer.Stop(); timer.Interval = TimeSpan.FromSeconds(RefreshTick.SelectedIndex); timer.Start(); }

 
but it says timer.Stop(); does not exist in the current context :/
 
Where in your code behind is timer declared? It will need to be declared at the global scope if you want to access it within RefreshTick_Change.
 
It's the ` DispatcherTimer timer = new DispatcherTimer();` under my public MainWindow(){ . . . .} code
 
So it is both declared and defined in constructor MainWindow. DispatchTimer timer; It needs to be a declared at global scope (where you can also define it e.g. = new DispatchTimer(). Or you can continue to define it in MainWindow's constructor. But it must be declared at global scope.
 
I see now; but now the values aren't refreshing at all... Am I missing something? I declare DispatchTimer globally, and call the timer.Stop etc in the RefreshTick_Change method
 
11:20 PM
Not sure what you mean by the values aren't refreshing, but check to see if timer_Tick is being called at the proper interval.
You there?
 
Hi there
I seemed to have forgotten to add timer_Tick back in
and then all I needed was converting the tick value to 1 extra second
timer.Interval = TimeSpan.FromSeconds(cbFrequency.SelectedIndex +1);
Else it would generate values every 0 seconds (not great)
 
Sounds like you've got it figured out. And yes, should have have the SelectedIndex +1 in the code of my answer.
 
    public void cbFrequency_Change(object sender, SelectionChangedEventArgs e)
    {
        timer.Stop();
        //Takes the ComboBox value and converts it to seconds - plus one is for the starting at 0 convention
        timer.Interval = TimeSpan.FromSeconds(cbFrequency.SelectedIndex +1);
        timer.Start();
        timer.Tick += timer_Tick;
    }
Thanks ever so much for your help :)
 
Just edited my answer for the +1. have to run to a meeting now though. Bye!
 
Bye
 

last day (15 days later) »