Search code examples
silverlightsilverlight-3.0controlsformatting

Enable or Disable multiple controls in Silverlight


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?


Solution

  • 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.