0
我在網格中有一個按鈕,我希望它在5秒後被禁用。我試圖通過計時器的Elapsed事件和啓用屬性來完成此操作。這裏是我的按鈕 -更新按鈕的定時器已消逝事件的狀態
<Window.DataContext>
<local:VM/>
</Window.DataContext>
<Grid>
<Button Content="Button" Command="{Binding ACommand}"/>
</Grid>
,我有下面的代碼嘗試 -
public class VM
{
Timer timer;
public Command ACommand { get; set; }
public VM()
{
timer = new Timer(5000);
timer.Start();
timer.Elapsed += disableTimer;
ACommand = new Command(Do, CanDo);
}
bool CanDo(object obj) => timer.Enabled;
void Do(object obj) { }
void disableTimer(object sender, ElapsedEventArgs e)
{
timer.Stop();
timer.Enabled = false;
}
}
它保持5秒後啓用。
刷新狀態:http://stackoverflow.com/a/783121/4832634 –