views:

40

answers:

1

Hi

Let's say I have some Control that has been disabled. It contains a bunch of elements, but I want one of those child elements to remain enabled.

Something like this:

<ContentControl IsEnabled="False">
    <Border>
        <Button Content="Button" IsEnabled="True"/>
    </Border>
</ContentControl>

So in this example, the Button's IsEnabled="True" setting gets overridden by its parent. Is there a way of stopping this from happening?

This seems like a strange thing to be doing, but I have a situation where, when a Control is disabled and a user mouses down on it, I still want an event to be triggered.

I read in WPF Unleashed that wrapping something in a Frame control, "..isolates the content from the rest of the UI [and] properties that would normally be inherited down the element tree stop when they reach the Frame", but wrapping the Button in the example above in a Frame doesn't work.

Am I on the wrong track here?

+4  A: 

that's not inheritance, it's composition

the containing control is disabled, thus all of its contained controls are disabled

enable the container and the control that you want, and disable the other controls

Steven A. Lowe
@Steven: Thanks. "that's not inheritance, it's composition" Purely for interest's sake: In WPF Unleashed, Adam Nathan talks about "property value inheritance", which is a term he uses to refer to the flowing of property values down the element tree. So it seems to me that there is the term "inheritance", which most/all people use to refer to class-based inheritance, Nathan's "property value inheritance", and "composition" (which as far as I can see on MSDN, basically refers to UI layout?). Please correct me if I'm wrong. I'm trying to get a grip on the basics.
cfouche
@cfouche never read Nathan, but I suspect he's being somewhat loose with the terminology. Inheritance is semantics: a person is a mammal, a bicycle is a vehicle. Composition is containment and usage: the change in your pocket, the spark plugs within an engine. In this case, the containing control is like a box, if it won't open (is disabled) then naturally nothing 'inside' of it can be opened either. The same would hold for Visible (enabled/disabled is a weaker form of visible/not-visible); if the container is not visible, necessarily its contents are likewise invisible.
Steven A. Lowe