0
グリッド内にボタンがあり、5秒後に無効にしたいとします。私はTimerのElapsedイベントとEnabledプロパティでそれをしようとしました。ここに私のボタンである -タイマーの経過イベントの更新ボタンの状態
<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 –