Monday, December 10, 2012

IsEnabled for a container?

IsEnabled for a container?

Is there any way to disable all controls inside a container - grid for example? Thank you!

UPD: Although Silverlight's Grid has IsEnabled property, there is definitely no IsEnabled property for Windows phone 7 Grid.

Answers & Comments...

Answer: 1

After several days of trying to disable all chil contols inside Grid, I found following:

  1. There is no IsEnabled property for WP7 Grid
  2. We can still iterate throgh all children controls and set their IsEnabled property
  3. or we can use Visibility property for the Grid

Indeed, it doesn't make much sense showing controls if they are disabled, and it even saves some space and adds some interactivity when we hide and showe it reacting to users input. Agree that this is not very convincing answer, but the only one that I have so far :)

by : Bashir Magomedovhttp://stackoverflow.com/users/260905

Answer: 2

For Silverlight, I have added a ScrollViewer around the Grid. Since ScrollViewer inherits Control, I could set its IsEnabled property to false and that disabled all the controls inside the grid.

by : user969987http://stackoverflow.com/users/969987

Answer: 3

I have another option for you, using a StoryBoard. When your control is in certain state set the IsEnabled property of the container. This will disable the control. The state in the example below is the "ReorderEnabled" state. I used it to disable buttons on a listboxitem so the user can sort the items in the listbox.

                            <VisualState                                 x:Name="ReorderEnabled">                                 <Storyboard>                                     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Control.IsEnabled)" Storyboard.TargetName="ContentContainer">                                         <DiscreteObjectKeyFrame KeyTime="0">                                             <DiscreteObjectKeyFrame.Value>                                                 <System:Boolean>False</System:Boolean>                                             </DiscreteObjectKeyFrame.Value>                                         </DiscreteObjectKeyFrame>                                     </ObjectAnimationUsingKeyFrames>                                     <DoubleAnimation                                             Storyboard.TargetName="ContentContainer"                                             Storyboard.TargetProperty="Opacity"                                             To="0.5"                                             Duration="0"/>                                 </Storyboard>                             </VisualState> 

If you are not familiar with states. The best option to edit states is to use Expression Blend!

by : markwildehttp://stackoverflow.com/users/553589

Answer: 4

Wrap Grid or StackPanel with ContentControl. ContentControls has IsEnabled property.

by : Domen Koglerhttp://stackoverflow.com/users/1333142




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog