All entries for Saturday 01 October 2005

October 01, 2005

Application Command Provider

I decided to resurrect my CommandProvider component today. It should useful for a big project I'm currently working on. The component centralises the idea of an application "command" such as "New", "Open" or "Save". Usually in small applications people just put code in a menu item click event handler. The problem here is then when mutliple controls can invoke the same code. You usually end up with many event handlers all having to call one method. In addition, controlling the enabled/disabled state of each UI control linked to the command becomes non-trivial – even with data binding.

So my solution is a component to drop on a form that contains a list of available commands. (Each command also has Enabled and Checked properties.) The component implements IExtenderProvider and provides a Command property to other controls on the form. In addition it provides a CommandInvoker property that should be linked to a control's Click event for example. (EnabledProperty and CheckedProperty are also provided).

The form code just has to handle the CommandInvoked event of the CommandProvider. This typically is a switch block over the e.Command.Name value.

So I have no annoying event handlers for every damn menu item and toolbar button! And even cooler I can write "commandProvider.Commands["Save"].Enabled = false;" and the component will disable any controls set to the Save command.
In addition, data binding to Command objects makes keeping the UI consistent as simple as : "statusBar1.DataBindings.Add("Visible", commandProvider.Commands["StatusBar"], "Checked");"

I am wondering if this component has any commercial viability. I have put a fair amount of time into it and I believe could certainly improve the quality of larger .NET winform apps. I will have to research the market and see what else is out there…

Google Ads

Search this blog

Most recent comments

  • I scratched my eye while i was holding some kind of plastic packaging.. Anyways the corner of the pl… by Ercan on this entry
  • About a year ago my contacts that i was wearing, i guess were fautly, because shortly after they wer… by Jon on this entry
  • I got shower gel in my eye 4 and a half days ago, and becasue i rubbed my eyes a lot, i have scratch… by Chris on this entry
  • This website may help–health/tc/Eye–Injuries–Home–Treatment by S on this entry
  • I somehow got dirt, or debris in my eye. The terrible pain sent me in a tailspin. I was afraid of sa… by Bobbi on this entry


October 2005

Mo Tu We Th Fr Sa Su
Sep |  Today  | Nov
               1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30


Blog archive

Not signed in
Sign in

Powered by BlogBuilder