开发者

Enable/Disable WPF buttons depending on the number of clicks

I have two buttons

'btnPrev' and 'btnNext'

What I want to do is to be able to determine the numbe开发者_StackOverflowr of clicks of the button so that I could enable and disable them. The process is almost similar to 'paging' method.

Initial state: btnPrev - disabled, btnNext - enabled

1st Click (btnNext): btnPrev - enabled, btnNext - enabled

2nd Click (btnNext): btnPrev - enabled, btnNext - enabled

3rd Click (btnNext): btnPrev - enabled, btnNext - disabled

the idea is almost the same vice-versa (for btnPrev).


Store your page number as an int. You only need to know how many pages there are.

Then you'll have two boundary conditions:

  • int = 0 means prev is disabled, next is enabled.
  • int = maxPages - 1 means next is disabled, and prev is enabled.

Otherwise, both next and prev are enabled.

When they click next, increment the int by one. When they click prev, decrement it by one.


It sounds like that you create a wizard with 3 pages. You might consider another design to implement this wizard, in which a Controller handles the Workflow.

The ViewModel sample application of the WPF Application Framework (WAF) shows how this can be done.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜