views:

579

answers:

4

What is considered the best way of enabling or disabling multiple controls in Silverlight at the same time (textbox, combobox, autocompletebox and the like)?

  • I suppose I could bind the "IsEnabled" property of each control to a boolean property. That property only exists for interactive controls and not textblocks.

  • I could loop through the children recursively and set their properties appropriately, but that seems inelegant.

  • Ideally, I'd like to just set some disable-like property on the parent container of the controls, giving even the TextBlocks a disabled look similar to a Windows form.

Is there a way to just disable the parent container?

+1  A: 

Usually I always create a ControlHandler Class that does all the updates on my controls. (Just to separate concerns)

Recently we had to reset all controls on the form and didn't want to loop through every single control.

All control-related data logic gets updated in the ControlHandler class.

We then only apply the values appropriate values / properties onto our controls.

This is a workaround but worked pretty well and also cleanly for us.

There are, of course, better ways to solve that..

Shaharyar
Shaharyar... can you elaborate just a little? Are you looping through the controls from your ControlHandler class, or are your controls implementing this some other way? Thanks.
Traples
You could create your own controllers with a Handler-Interface which would be used to modify the controls. But that would mean to code a little more and extend each control you want to use and register it in a global / static list.What I did was fairly simple. I know which controllers I use so I just hard coded the values. Pointers in C# can also be used to accomplish that! You could make a function which takes (ref Controller c) arguments.
Shaharyar
+1  A: 

You could use a ViewModel approach similar to the answer in StackOverflow 1545844

By having a calculated IsEnabled property you can then bind the elements in the View which should be controled by this property.

Doug Ferguson
+1  A: 

I was looking into disabling multiple controls when fetching data from a web service. The BusyIndicator control got me what I needed with very little effort. Maybe it'll be a good enough solution for others as well.

Tony Emrud
A: 

Wrap with UserControl and set its IsEnabled property.

...