Is there any way to disable all controls inside a container - grid for example? Thank you!
UPD: Alth开发者_如何学Goough Silverlight’s Grid has IsEnabled property, there is definitely no IsEnabled property for Windows phone 7 Grid.
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.
Wrap the Grid or StackPanel with a ContentControl. ContentControls have an IsEnabled property.
After several days of trying to disable all child controls inside Grid, I found following:
- There is no IsEnabled property for WP7 Grid
- We can still iterate through all children controls and set their IsEnabled property
- We can also use the 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 show it according to users' input.
I agree that this is not very convincing answer, but it is the only one that I have so far. :)
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!
精彩评论