I'm stuck here. I have a checkbox. When checked, start timer. When unchecked stop timer. I can use some help here. I have tried checked, unchecked, and click events. Nothing is stopping the timer. It just keeps running...
Xaml: (has all three events just for show)
<CheckBox x:Name="CbAutoRefresh" Grid.Row="1" ClipToBounds="True" HorizontalAlignment="Left" Content="Enable Auto Refresh" Margin="10,0,0,0" Width="150" Click="CbAutoRefresh_Click" Checked="CbAutoRefresh_Checked" Unchecked="CbAutoRefresh_Unchecked" />
C#: (all three attempts)
private void CbAutoRefresh_Click(object sender, RoutedEventArgs e)
{
var aTimer = new Timer();
if (CbAutoRefresh.IsChecked == true)
{
//start a timer:
aTimer.Elapsed += OnTimedEvent;
aTimer.Interval = 60000;
aTimer.Enabled = true;
}
else
{
aTimer.Enabled = false;
}
}
private void CbAutoRefresh_Checked(object sender, RoutedEventArgs e)
{
//start a timer:
var aTimer = new Timer();
aTimer.Elapsed += OnTimedEvent;
aTimer.Interval = 60000;
aTimer.Enabled = true;
}
private void CbAutoRefresh_Unchecked(object sender, RoutedEventArgs e)
{
var aTimer = new Timer {Enabled = false};
}
I even tried this, which was mention at Stack Overflow
<CheckBox Checked="CheckBoxChanged" Unchecked="CheckBoxChanged"/>
private void CheckBoxChanged(object sender, RoutedEventArgs e)
{
MessageBox.Show("Eureka, it changed!");
}
Aucun commentaire:
Enregistrer un commentaire