Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop property values from flowing down the element tree in xaml?

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?


1 Answers

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

like image 157
Steven A. Lowe Avatar answered Jan 22 '26 06:01

Steven A. Lowe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!