Getting Attached property inheritance to propagate

天涯浪子 提交于 2019-12-05 21:39:55
Philip Rieck

This should work fine, according to the docs on Property Value Inheritance. Make sure that your call to register the property looks like:

public static readonly DependencyProperty IsChecked = 
    DependencyProperty.RegisterAttached(
    "IsChecked",
    typeof(Boolean),
    typeof(AttachedToggle),
    new FrameworkPropertyMetadata(false, 
        FrameworkPropertyMetadataOptions.Inherits)
  );

-Note the Inherits flag. See the docs for FrameworkPropertyMetadata (and FrameworkPropertyMetadataOptions - you can use OverridesInheritanceBehavior if needed ) as well.

Im not sure that attached properties propogate down the logical tree, but you could try something like this:

<Panel a:ToggleSwitch="Binding Path=(a:ToggleSwitch), 
           RelativeSource={RelativeSource Mode=FindAncestor, 
           AncestorType={x:Type Panel}}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!