开发者

DispatcherTimer blocks the UI from being updated?

I have two Buttons i开发者_如何学Cn the View, one for recording some sound, one plays the recording when recording is done. When recording is done, I set the VM property of recording_done to 1, which is used for CanPlay(), which enables the Play button. Everything works fine so far.

I added a timer to auto stop the recording after two seconds. after some trials and errors, I settled with a DispatcherTimer. My problem is the UI (Play button) does not gets enabled until I clicked the WPF window (somewhere/anywhere on the windows). Clearly the debug msg says the recording_done is set to 1. That should trigger the UI update, but it does not, until I clicked on the windows.

I tried both ways, 1. Recording button bind to Command in ViewModel, there I start the timer and stop the timer. 2. put the recording button handler and timer code in the view's code behind. similar problems.

Any suggestion? Is this a threading/UI update issue? Thanks.


If your play button is bound to a command, and the CanExecute() of the command is bound indirectly to the recording_done property or field, it won't update until the CanExecuteChanged event on the ICommand is raised, or until WPF decided to requery the commands. I suspect this is the problem - you need to have the ICommand raise CanExecuteChanged.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜