开发者

UI Design Question - Controls Hiding and Showing

I have a Winform in my application. the form contains lots of controls ranging from Radio Buttons .. to text boxes to buttons to check boxes. One of the requirement is that based on the type of license mode certain option should be shown or hidden or enabled or disabled.

Say for exmample the applcation has two license modes: 1) Normal 2) advanced

In normal mode only few controls need to be displayed say only 3 text boxes and 2 buttons. and few checkboxes

in advanced mode all items needs to be displayeed and only few checkboxes shall be allowed to be editable.

Currently i have done it directly in the code... I am sure in futire there would be more controls added / removed or made into advanced modes and stuffs !

Can i design the enabling and disabling in a simple fashion ... may be i get the list of controls need to be disabled or enabled based on a XML file. ?

Any help on the design would be apprec开发者_如何学JAVAiable.


If you're using a controller for the UI, the 'show/hide' logic should be kept in the controller (it is a business rule). I use properties such as 'CanCurrentUserSeeEditButton' in the controller to determine whether a control should be visible, then in the UI I using data-binding to set the controls 'Visible' or 'Enabled' properties to bind to the controller logic (INotifyPropertyChanged is implemented for all controller properties).

This means I can unit-test the enabled/visible logic without the UI.

This doesn't help automate the addition of new controls, but makes it easier to keep track if what's needed for each new control.


I might be tempted to add an extension property provider, so you can simply set a new pseudo-property that appears in the IDE property panel.

A similar example (using the "principal" for roles-based checks) is shown here.

Note, however, that it would be pretty easy for someone with programming knowledge to bypass anything simple.


I would use two block (like groups or something) one for normal and one for advanced, this way you can only hide the whole block. Something like:

+ Normal options ----------------------------+
| ( ) check this to ..                       |
| Name: [                    ]               |
+--------------------------------------------+

+ Advanced options --------------------------+
| IP: [               ]                      |
| Host: [                    ]               |
| Mode: ( ) ...                              |
|       ( ) ...                              |
+--------------------------------------------+


I am not sure if it is a good practice, but if the number of modes is not very big, like 3 or 4, you can create several user controls and then paste them directly to your main form dynamically when needed.

This way is rather convenient - you can easily maintain all the future changes in separate controls. The only problem is to transfer data when loading controls, but it can be solved as well with some additional properties or methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜