# Disable Command Source via System Timer Sample
This sample shows how to enable and disable a command source via a Windows.System.Timers.Timer.
A Windows.System.Timers.Timer runs on a separate thread than the UI thread, so some extra work is needed to update the UI. Another way to solve this problem, and in most cases a better and more elegant way, is a use the DispatcherTimer. This is easier because the DispatcherTimer runs on the same thread as the UI Thread. For information, see the Disable Command Source via Dispatcher Timer Sample sample. There are times though when you may need to use a class that doesn't run on the UI thread, so this sample shows how to accomplish this.
Command sources, such as the MenuItem class and the Button class, listen to the CanExecuteChanged event on the RoutedCommand they are attached to in order to determine when they need to query the command to see if the command can execute on the current command target. Command sources will typically disable themselves if the command cannot execute and enable themselves if the command can execute, such as when a MenuItem gray's itself out when the command cannot execute.
The CommandManager notifies the RoutedCommand via the RequerySuggested event that conditions have changed with the command target. The RoutedCommand raises the CanExecuteChanged event which the command source listens to. Normally, this notification mechanism is adequate, but there are some situations where the CommandManager is unaware that the conditions have changed on the command target and thus the RequerySuggested event is never raised and the command source never queries the RoutedCommand. In these situations the CommandManager can be forced to raise the RequerySuggested event by calling InvalidateRequerySuggested.
## Build the sample
The easiest way to use these samples without using Git is to download the zip file containing the current version (using the link below or by clicking the "Download ZIP" button on the repo page). You can then unzip the entire archive and use the samples in [Visual Studio 2015](https://www.visualstudio.com/wpf-vs).
### Deploying the sample
- Select Build > Deploy Solution.
### Deploying and running the sample
- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or selectDebug > Start Without Debugging.
没有合适的资源?快使用搜索试试~ 我知道了~
WPF实例程序,命令,动画,资源,本地化等等
共2000个文件
cs:1630个
xaml:642个
resx:246个
1星 需积分: 12 23 下载量 3 浏览量
2017-11-16
13:22:40
上传
评论
收藏 26.36MB ZIP 举报
温馨提示
官方实例,WPF实例程序,命令,动画,资源,样式及模板,本地化,拖拽,绑定,希望对初学WPF的童鞋有用...
资源推荐
资源详情
资源评论
收起资源包目录
WPF实例程序,命令,动画,资源,本地化等等 (2000个子文件)
hwndinwpf.aps 52KB
tulipfarm.bmp 900KB
solarsystem.bmp 25KB
hwndInWPF.vcxprojResolveAssemblyReference.cache 12KB
copydata.cmd 99B
App.config 2KB
App.config 389B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
App.config 184B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- lnsy1392018-01-10下载中断,没成功,重下newords2018-02-05下载中断怪我咯!
newords
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功