How to stop property values ​​from an element tree stream in xaml?

Say I have a control that has been disabled. It contains a bunch of elements, but I want one of these child elements to remain on.

Something like that:

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

Thus, in this example, the Button IsEnabled = "True" parameter is overridden by its parent. Is there any way to stop this?

This seems like a strange thing, but I have a situation where, when the control is disabled, and the mouse user descends on it, I still want the event to be fired.

I read in WPF Unleashed that I was wrapping something in the Frame control, "..deletes the contents of the remaining interface properties [and], which are usually inherited down the element tree when they reach the frame," but the button wrapper in the example above in frame does not work.

Am I on the wrong track here?

+3
source share
2 answers

what is not inheritance, its composition

the containing control is disabled, so all its contained controls are disabled

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

+5
source

( , ), CoerceValue, ( , , IsEnabled IsChecked, bool?, null , ... , ):

public sealed class InheritedButton:
  Button
{
  static InheritedButton()
  {
    InheritedButton.IsEnabledProperty.OverrideMetadata
    (
      typeof(InheritedButton),
      new FrameworkPropertyMetadata
      (
        true,
        null,
        _CoerceIsEnabled
      )
    );
  }
  private static object _CoerceIsEnabled(DependencyObject source, object value)
  {
    return value;
  }
}
+4

Source: https://habr.com/ru/post/1737036/


All Articles