Reputation: 103
I have a Silverlight project. In the project I have a UserControl. IsEnabled for this UserControl is set dynamically and most of the time it is set to false.
In this UserControl, I have a several nested grids and all the grids inherit the IsEnable from their parent (UserControl) as usual.
However, for one of the grids inside this UserControl, I don't want to inherit this feature. I want to set it True always. Is there a way to override the IsEnabled feature?
What I tried is, I wrap with ContentControl and I set IsEnabled to True, but it did not work.
<ContentControl IsEnabled="True">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="0,0,0,0" BorderThickness="0">
<HistoryControls:EditableMAMGridContainer StateInfo="{Binding Path=StateInfo, Source={StaticResource Evm}}" />
</ScrollViewer>
</ContentControl>
The root is UserControl for this Scrollviewer and it has several parents and grandparents. It is in the very deep.
EDIT: This code works but vice-versa does not work
<UserControl IsEnabled="True">
.
.
<ContentControl IsEnabled="False">
...
when UserControl sets False, and contentControl sets True (opposite case of the above code) then does not work.
Upvotes: 0
Views: 212
Reputation: 6162
First of all: if you disable the parent, all the children are disabled. Period. You cannot change this, and this is actually a good thing. Because this way you can be absolutely sure to reliably block all user input to an entire subtree of the UI.
Don't try to bend the concepts of the framework. The concept here is: disabled absolutely means there cannot be any user input! In no part of it, not the tiniest corner of that subtree.
If we follow this concept then it will quickly become clear to us that you actually don't want your parent to be disabled, because obviously you want a small portion of it to still receive user input. So -conceptually- it is not disabled!
Now how to translate that technically?
It means you will have to structure you tree in a way that lets you disable one branch of it while at the same time have a sibling branch still be enabled.
Example
<TravelBooking>
<!-- this will be disabled if we don't travel by plane -->
<TransferToAirportPlanner/>
<FlightToDestinationPlanner/>
<ReturnFlightPlanner/>
<TransferFromAirportPlanner/>
<!-- this will always be enabled -->
<HotelPlanner/>
</TravelBooking>
Restructured tree to allow for disabled subtree
<TravelBooking>
<!-- this will be disabled if we don't travel by plane -->
<AirplaneTravelPlanningControl>
<TransferToAirportPlanner/>
<FlightToDestinationPlanner/>
<ReturnFlightPlanner/>
<TransferFromAirportPlanner/>
</AirplaneTravelPlanningControl>
<!-- this will always be enabled -->
<HotelPlanner/>
</TravelBooking>
Now you can easily disable the AirplaneTravelPlanningControl to disable the contained subtree.
Upvotes: 4